可能重複:
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