[英]java class initialization explanation
我是Java的新手,如果有人可以向我解釋以下代碼示例,我將非常高興。這只是一個示例Java代碼段。 但是主要的問題是,如果Learn類使用參數也是Object類來初始化另一個Smart類,那么在類Object Sample中添加點類會使我感到困惑。 任何解釋將不勝感激。 抱歉,這是一個基本問題。 謝謝。
class Learn {
//some codes
Smart smart = new Smart(Sample.class);
//some codes
}
Sample
是類的名稱。 它不是對象。 一個new Sample()
是一個對象,其類為Sample
。 Sample.class
是一個對象,其類為java.lang.Class
,它描述類Sample
。
我將通過以下方式打破您的榜樣。
學習-是一Class
smart-是Smart
類型的Object Reference Variable
,可以說Class Learn具有Smart類型的引用。
Sample.class-一種獲取特定類型的Class<T>
的方法。
從Java文檔中提取。
During implementation it depends on the Targeting bytecode version. If -target 1.4 (or
During implementation it depends on the Targeting bytecode version. If -target 1.4 (or
below), a call to Class.forName() is inserted into your code in a static method which is
called during type initialization. If you use -target 1.5 (or above) the constant pool
below), a call to Class.forName() is inserted into your code in a static method which is
called during type initialization. If you use -target 1.5 (or above) the constant pool
called during type initialization. If you use -target 1.5 (or above) the constant pool
gets a "class" entry
有關更多詳細信息,請參閱Java語言規范的15.8.2節。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.