I understand what wrappers are, but from the documentation you seem to be able to get an instance of a Class object of type int. Does this return the wrapper or some sort of Class instance of int? Because it wouldn’t make sense if it did, due to generics and type erasure. Isn’t it true that you can only get Class instances of actual classes not primitives? When they say represent do they mean wrapper of something else?
Here is what the JavaDoc says, and why I’m confused
TYPE
public static final Class TYPE
The Class instance representing the primitive type int.
Since:
JDK1.1
Sort of.
But sometimes you need to have some meta-data for “primitive integer”. For example when looking at the method signature. Then you get a
Class[]for the parameters, and you somehow need to differentiate betweenpublic void test(Integer x)andpublic void test(int x).So to facilitate this, there are special Class instances for the primitive types.
To take this a step further, there is even java.lang.Void.TYPE:
Insightful Javadoc: