shallow heap例說

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字節。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章