Home > Java > JavaBase > 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

Release: 2019-12-04 11:23:24
Original
7927 people have browsed it

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");
}
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template