比如我有两个类,分别是TestA 和 TestB
public class TestA {
public List<String> list = new ArrayList<String>();
}
public class TestB {
public static void main(String[] args) {
TestA a = new TestA();
a.list.add("Test");
}
}
我看书的时候说所有的reference都保存在栈中,而new出来的对象属性 包括全局属性都保存在堆中, 那么a应该是保存在栈里面,而new出来的TestA中的list这个Reference保存在堆还是栈啊,很困惑。
希望各位大侠解惑,谢谢