10

I want to know the difference between int.class and Integer.TYPE in Java?

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Maverick
  • 3,053
  • 6
  • 24
  • 30
  • 2
    Does this answer your question? [Integer.class vs int.class](https://stackoverflow.com/questions/22470985/integer-class-vs-int-class) – limido Oct 06 '20 at 10:22

3 Answers3

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