I want to know the difference between int.class and Integer.TYPE in Java?
Asked
Active
Viewed 1,708 times
3 Answers
16
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);
}
}

Jack Edmonds
- 31,931
- 18
- 65
- 77
5
The .class keyword get the Class object represent both primitive types and class types, while the .TYPE field of the wrapper primitive class allows you to get the Class of the primitive type which that object wraps.

aleroot
- 71,077
- 30
- 176
- 213
1
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

giuseppe giusti
- 11
- 2