user3380123 user3380123 - 9 days ago 5
Java Question

Integer.class vs int.class

What is the difference between

Integer.class
,
Integer.TYPE
and
int.class
?

acc to me


  1. Integer.class
    is a reference of Integer (Wrapper) Class object

  2. but what is then
    int.class
    as
    int
    is not a class, it's a primitive type. And what does
    Integer.TYPE
    refer to?


Answer

From java.lang.Class.isPrimitive API

There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double.

These objects may only be accessed via the following public static final variables java.lang.Boolean.TYPE, java.lang.Integer.TYPE etc

Comments