Instanceof is a simple two-dollar operator that is used to determine whether an object is an instance of a class
Boolean B1 = "Sting" instanceof Object;
B1 is true because string is a subclass of object
Boolean b2 = new string () instanceof string;
B2 is true
Boolean b3 = new Object () instanceof String;
B3 to false object is a parent class
Boolean b4 = ' A ' instanceof Character;
compilation does not pass ' A ' is considered a basic data type here char,instanceof operator can only be used as an object's judgment
Boolean b5 = null instanceof String;
B5 to false this is a instanceof-specific rule: if the left-hand operand is null, the result is returned directly to false, no longer the class of the right-hand operand.
Boolean b6 = (string) null instanceof String;
B6 to false even if the type conversion is still a null
Boolean B7 = new Date () instanceof String;
compilation does not pass the left and right operands of the instanceof operator must have an inheritance or implementation relationship, or else compilation error
Boolean B8 = new Genericclass<string> (). Isdateinstance ("");
Class genericclass<t>{
public boolean isdateinstance (T-t) {
return T instanceof Date;
}
compilation passed , B8 to false because of generics, so the time of bytecode is the object type, where T instanceof date is equivalent to object instance of date.