Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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

like image 268
Maverick Avatar asked Jan 06 '12 14:01

Maverick


2 Answers

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);
    }
}
like image 53
Jack Edmonds Avatar answered Oct 04 '22 21:10

Jack Edmonds


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.

like image 36
aleroot Avatar answered Oct 04 '22 22:10

aleroot