Java-第 0 个局部变量何时不是 'this'?

标签 java bytecode

在Java方法的局部变量中,第0个局部变量什么时候不引用'this'?

我可以认为静态方法是一个反例,还有其他的吗?

更新:我指的是字节码

最佳答案

JVM specification section 2.6.1似乎认为它只取决于它是静态(类)方法还是实例方法:

The Java Virtual Machine uses local variables to pass parameters on method invocation. On class method invocation, any parameters are passed in consecutive local variables starting from local variable 0. 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). Any parameters are subsequently passed in consecutive local variables starting from local variable 1.

这是根据局部变量的初始值;请参阅 Mike Strobel 的回答以获取在方法期间明确更改的示例。

关于Java-第 0 个局部变量何时不是 'this'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22174994/

相关文章:

java - 为什么泛型类和方法声明中不能使用通配符?

java - 如何将 Java 中的 TIFF 图像读入 BufferedImage?

java - JAR 执行不接受 Walmart Developer API 身份验证所需的参数

java - 从外部 jar 文件中卸载的类中读取字节码

actionscript-3 - ActionScript ByteCode AVM2 中的堆栈、寄存器,都有哪些?

java - 在运行时(动态地)创建简单的 POJO 类(字节码)

java - Android - 构建 list 中出现神秘权限

java - 如何使用 BCEL 更改静态字段的值?

java - 在 Java 字节码中替换实例的(类)类型的优雅方法

java - 如何让 javafx 14 编译并运行?