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