我昨天看到一个问题,提出了(对我来说)另一个问题。请看下面的代码:类的字段,它们是存储在堆栈还是堆?
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