A one-time fix instanceof and isinstance,instanceof and isinstance are very similar, and the usage is similarly, first look at these two usages:
Obj.instanceof (Class)
Which means that this object is not of this type,
1. An object is an object of its own class
2. An object is an object of its own class parent class (parent of the parent Class) and interface (interface of the interface)
3. All objects are object
4. All null-related is False null.instanceof (class)
Class.ininstance (obj)
Can this object be converted into this class?
1. An object is an object of its own class
2. An object can be converted to an inherited class of its own class (the parent class of the parent class, etc.) and the implemented interface (the parent interface of the interface) strongly turns
3. All objects can be strongly transferred by the object
4. All null-related is false class.ininstance (NULL)
Class name. class and object. GetClass () is almost indistinguishable, because a class is the only class that is loaded by the ClassLoader.
An example is done:
classA {}classBextendsA {} Public classTest { Public Static voidMain (string[] args) {b b=NewB (); A A=NewA (); A BA=NewB (); System.out.println ("1------------"); System.out.println (binstanceofB); System.out.println (binstanceofA); System.out.println (binstanceofObject); System.out.println (NULL instanceofObject); System.out.println ("2------------"); System.out.println (B.getclass (). Isinstance (b)); System.out.println (B.getclass (). Isinstance (a)); System.out.println ("3------------"); System.out.println (A.getclass (). Isinstance (BA)); System.out.println (B.getclass (). Isinstance (BA)); System.out.println (B.getclass (). Isinstance (NULL)); System.out.println ("4------------"); System.out.println (A.class. Isinstance (a)); System.out.println (A.class. Isinstance (b)); System.out.println (A.class. Isinstance (BA)); System.out.println ("5------------"); System.out.println (B.class. Isinstance (a)); System.out.println (B.class. Isinstance (b)); System.out.println (B.class. Isinstance (BA)); System.out.println ("6------------"); System.out.println (Object.class. Isinstance (b)); System.out.println (Object.class. Isinstance (NULL)); }}
Operation Result:
Instanceof and isinstance differences in Java