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.
本文解释了Java 1.1中引入.class关键字的原因,为了保持获取原始类型和包装类类型的Class对象的一致性。文中还通过示例说明了如何使用该关键字来获取Class对象。

被折叠的 条评论
为什么被折叠?



