我昨天看到一個問題,提出了(對我來說)另一個問題。請看下面的代碼:類的字段,它們是存儲在堆棧還是堆?
public class Class1
{
int A; //as I uderstand, int is value type and therefore lives in the stack
}
class Class2
{
Run()
{
Class1 instance1 = new Class1();
instance1.A = 10; //it points to value type, but isnt this reference (on heap)?
}
}
或者在創建Class1的實例時,它的字段類型也在堆上創建?但是,我不明白什麼時候它真的會在堆棧上,因爲幾乎總是需要創建一個對象的實例才能使用它的字段。
類名是不允許的題外話,開始與多家 – cpalmer 2010-04-02 06:35:26
:你有沒有 – thelost 2010-04-02 06:36:49
感謝了無效類的名稱,固定的:) – Mirek 2010-04-02 06:36:57