// obj instanceof Tboolean result;if (obj == null) { result = false; } else { try { T temp = (T) obj; // checkcast result = true; } catch (ClassCastException e) { result = false; } }
Instanceof is a binary operator in Java, which is the same type as ==, >, <. Since it is composed of letters, it is also a reserved keyword in Java. Its function is to test whether the object on its left is an instance of the class on its right, and return boolean type data
The instanceof
operator in java is used to indicate whether the object is a specific class at runtime an instance of. instanceof returns a Boolean value indicating whether the object is an instance of this specific class or a subclass of it.
Usage:
result = object instanceof class
Parameters:
Result: Boolean type.
Object: required. Any object expression.
Class: required. Any defined object class.
Description:
If object is an instance of class
, the instanceof operator returns true. Returns false if object is not an instance of the specified class, or if object is null.
The above is the detailed content of In this way, the instanceof keyword can be implemented. For more information, please follow other related articles on the PHP Chinese website!