昨天我看到了一个问题,它引发了我另外一个问题。请看下面的代码:
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实例时,它的字段类型也会在堆上创建吗?但是我不明白它什么时候会真正地在栈上,因为你几乎总是需要创建对象实例才能使用它的字段。