In Java it is valid to have a class literal for primitives like int.class. Was this allowed even prior to the introduction of auto boxing feature in Java ? What does the object that we get out of int.class contain actually ? Why is it valid ?
2 Answers
int is not a class, so int.class doesn't really make sense.
The reason is they went cheap, and used one Class to represent all types. So for example, Method.getReturnType() returns a Class, which could actually represent a class, or a primitive, an array, or even void.
That was sort of fine, before generics, since there weren't too many kinds of types. After generics, things get really messy, the new Type hierarchy makes even less sense, since it incorporates the old messy Class; as a result the tree of Types looks nothing like the tree of types in the language spec.