Home  >  Article  >  Java  >  Introduction to the method of determining whether a variable is of type int in java

Introduction to the method of determining whether a variable is of type int in java

尚
Original
2019-12-04 11:23:247807browse

Introduction to the method of determining whether a variable is of type int in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn