在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/