The creation process of java objects-coding demonstration

Source code

class T {
    int m = 8;
}

T t = new T();

Assembly code

0 new #2 <T> //在堆中为对象开辟空间,并且为属性附零值(0或null),m=0
3 dup  
4 invokespecial #3 <T.<init>> //调用构造函数,并对属性赋值,此例是m=8
7 astore_1 //将创建好的对象地址,赋值给变量t
8 return

 

Guess you like

Origin blog.csdn.net/weixin_44182586/article/details/108817056