简体   繁体   中英

What is difference between int.class and Integer.TYPE in java?

我想知道Java中的int.class和Integer.TYPE之间的区别?

Absolutely nothing. If you run the following code, you will see that int.class is the same thing as Integer.TYPE .

public class Test {
    public static void main(final String[] args) {
        System.out.println(int.class == Integer.TYPE);
    }
}

.class关键字获取Class对象表示基本类型和类类型,而包装器基元类.TYPE字段允许您获取该对象包装的基本类型的Class

absolutely false check this :

  public static void main(String[] args) {
            System.out.println(int.class.equals(Integer.TYPE));
            System.out.println(Integer.class.equals(Integer.TYPE));
        }

output : true false

Boolean.TYPE == boolean.class 
Byte.TYPE == byte.class 
Short.TYPE == short.class 
Character.TYPE == char.class 
Integer.TYPE == int.class 
Long.TYPE == long.class 
Float.TYPE == float.class 
Double.TYPE == double.class 
Void.TYPE == void.class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM