【发布时间】:2014-11-19 04:55:51
【问题描述】:
假设我们有以下代码:
void method() {
int[] test = new int[3];
test[0] = 0;
test[1] = 1;
test[2] = 2;
}
根据我从Jon Skeet's post on SO 中读到的内容,new int[3] 部分相当于:
public class ArrayInt3 {
public readonly int length = 3;
public int value0;
public int value1;
public int value2;
}
这是否意味着test(对ArrayInt3 的引用)在堆栈中?这是否意味着ArrayInt3 在堆上?我想value0、value1 和value2 也在堆上(即本例中的 0、1、2)?
所以堆上总共有 4 个对象,对吗?
【问题讨论】:
标签: java arrays heap-memory stack-memory