JVM method translate to bytecode:修订间差异

来自WHY42
第36行: 第36行:
invokespecial #6                  // Method "<init>":()V
invokespecial #6                  // Method "<init>":()V
</syntaxhighlight>
</syntaxhighlight>
== 变量赋值 ==
<syntaxhighlight lang="java">
HelloWorld s = new HelloWorld();
</syntaxhighlight>
<syntaxhighlight lang="lisp" highlight="4">
new          #5                  // class HelloWorld
dup
invokespecial #6                  // Method "<init>":()V
astore_1
</syntaxhighlight>


[[Category:JVM]]
[[Category:JVM]]

2021年4月20日 (二) 08:48的版本

特殊方法

xxx

默认构造函数

aload_0
invokespecial #1                  // Method java/lang/Object."<init>":()V
return

其中,

  • 构造函数会通过invokevirtual被调用,这里aload_0可以取到this
  • 构造函数中会去调用父类的构造函数

statements

创建对象

HelloWorld s = new HelloWorld();
new           #5                  // class HelloWorld
dup
invokespecial #6                  // Method "<init>":()V

变量赋值

HelloWorld s = new HelloWorld();
new           #5                  // class HelloWorld
dup
invokespecial #6                  // Method "<init>":()V
astore_1