What are the differences between e.g., int.class, Integer.class, Integer.TYPE, and Integer's getClass() method?

John Mitchell

The .class keyword was added in Java v1.1 so that there would be consistency in getting to the Class objects representing both primitive types and class types. The .TYPE field of the various object wrapper classes of primitive types allows you to "go backwards" to get to the Class of the primitive type which that object wrapper "wraps".

We have int.class == Integer.TYPE and Integer.class == (new Integer(0).getClass()).

So, for consistency and simplicity, use the .class keyword to get the Class object.