gpt4 book ai didi

java - 为什么非静态方法有额外的Local?还有,这是什么?

转载 作者:行者123 更新时间:2023-12-02 06:19:21 25 4
gpt4 key购买 nike

根据我对方法 1 中定义的每个局部变量的理解,local 是为此 Locals 指示器添加的。

来源:

public class A {
public void a() {}

public static void b() {}
}

生成的字节码:

Compiled from "A.java"
public class A extends java.lang.Object
SourceFile: "A.java"
minor version: 0
major version: 50
Constant pool:
const #1 = Method #3.#12; // java/lang/Object."<init>":()V
const #2 = class #13; // A
const #3 = class #14; // java/lang/Object
const #4 = Asciz <init>;
const #5 = Asciz ()V;
const #6 = Asciz Code;
const #7 = Asciz LineNumberTable;
const #8 = Asciz a;
const #9 = Asciz b;
const #10 = Asciz SourceFile;
const #11 = Asciz A.java;
const #12 = NameAndType #4:#5;// "<init>":()V
const #13 = Asciz A;
const #14 = Asciz java/lang/Object;

{
public A();
Code:
Stack=1, Locals=1, Args_size=1
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 1: 0


public void a();
Code:
Stack=0, Locals=1, Args_size=1
0: return
LineNumberTable:
line 6: 0


public static void b();
Code:
Stack=0, Locals=0, Args_size=0
0: return
LineNumberTable:
line 11: 0


}

最佳答案

它是当前对象,又名this。来自 the JVM Spec §3.6.1 Local Variables :

On instance method invocation, local variable 0 is always used to pass a reference to the object on which the instance method is being invoked (this in the Java programming language).

关于java - 为什么非静态方法有额外的Local?还有,这是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5855457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com