Use the instanceof keyword in java to determine whether it is an int: (Recommended: java video tutorial)
Integer i = 0; if (i instanceof Integer) { System.out.println("haha"); }
instanceof Strictly speaking, it is in Java A binary operator used to test whether an object is an instance of a class. The usage is:
boolean result = obj instanceof Class
where obj is an object, and Class represents a class or an interface. When obj is an object of Class, Either its direct or indirect subclass, or the implementation class of its interface, the result returns true, otherwise it returns false.
Note: The compiler will check whether obj can be converted to the class type on the right. If it cannot be converted, an error will be reported directly. If the type cannot be determined, it will be compiled. It depends on the runtime.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Introduction to the method of determining whether a variable is of type int in java. For more information, please follow other related articles on the PHP Chinese website!