What makes an object assignment-compatible with another class?

前端 未结 5 1395
借酒劲吻你
借酒劲吻你 2021-01-15 01:43

I\'m wondering what specifically allows an object of one class to be cast as another class. Looking at the Class.isInstance(Object obj) javadoc, it suggests that an object

5条回答
  •  我在风中等你
    2021-01-15 02:16

    Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:

     Object x = new Integer(0);
     System.out.println((String)x);
    

    more info here and here.

提交回复
热议问题