2 回答

TA贡献1859条经验 获得超6个赞
public final Class<?> getClass()
Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class.
The actual result type is Class<? extends |X|> where |X| is the erasure of the static type of the expression on which getClass is called. For example, no cast is required in this code fragment:
Number n = 0;
Class<? extends Number> c = n.getClass();
Returns:
The Class object that represents the runtime class of this object.
See Also:
The Java Language Specification, Third Edition (15.8.2 Class Literals)
还不理解?看中文翻译
public final Class<?> getClass()返回此 Object 的运行时类。返回的 Class 对象是由所表示类的 static synchronized 方法锁定的对象。
实际结果类型是 Class<? extends |X|>,其中 |X| 表示清除表达式中的静态类型,该表达式调用 getClass。 例如,以下代码片段中不需要强制转换:
Number n = 0;
Class<? extends Number> c = n.getClass();
返回:
表示此对象运行时类的 Class 对象。
另请参见:
The Java Language Specification, Third Edition (15.8.2 Class Literals)
添加回答
举报