可能重复:
What’s the difference between calling MyClass.class and MyClass.getClass()的getclass()VS的.class
希望有一个Class<T>
对象,这是这两种方法之间的区别?
Test ob = new Test();
ob.getclass();
或
Test.class
可能重复:
What’s the difference between calling MyClass.class and MyClass.getClass()的getclass()VS的.class
希望有一个Class<T>
对象,这是这两种方法之间的区别?
Test ob = new Test();
ob.getclass();
或
Test.class
getClass()
方法在java.lang.Object
中定义,因此可以在任何对象引用上调用。
它获取与引用指向的对象的运行时类型相关联的Class对象。 。
getClass()方法根本不类似于.class。 Closer是Class.forName(String),它获取由String命名的类的Class对象。
在可以使用任一种情况下,使用.class
,因为它更有效。
重复:[http://stackoverflow.com/q/2467970/1225328](http://stackoverflow.com/q/2467970/1225328) – sp00m