public class Person{
String name;
int age;
public Person(String a, int b){
name = a;
age = b;
}
}
上面類實例的shallow heap是16,因爲對象頭是8字節,成員變量int是4字節、String引用是4字節,故總共16字節。
public class Person{
String name;
int age;
public Person(String a, int b){
name = a;
age = b;
}
}
上面類實例的shallow heap是16,因爲對象頭是8字節,成員變量int是4字節、String引用是4字節,故總共16字節。