Java, difference between Integer.TYPE and int.class

Asked

Viewed 79 times

2

What is the difference between using Integer.TYPE and int.class?

I did some tests and both can be passed as a parameter to a Class<?>.

  • As far as I know, it’s all the same Class. If I find any reference confirming this, put as answer.

1 answer

2


Integer.TYPE and int.class are the same thing.

If you run the following snippet, you will see that the return is true.

System.out.println(Integer.TYPE.equals(int.class));

The definition of Integer.TYPE is as follows::

public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.