如何从Java字节码中判断局部变量是否为“最终”? (与BCEL有关) [英] How can one tell if a local variable is 'final' from Java bytecode? (Related to BCEL)

查看:109
本文介绍了如何从Java字节码中判断局部变量是否为“最终”? (与BCEL有关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里有信息(例如,本地变量是否以Java字节码存储在 final中)?我知道对于字段(全局变量)和方法来说,这些都是在访问标志位中找到的,但是似乎无法在局部变量表中找到等效项。



我是对这个问题感兴趣,因为我正在使用BCEL检查局部变量是否为最终变量,并在AccessFlags类中找到与字段,方法和类等效的变量。



谢谢

解决方案

局部变量的确定性由编译器检查,并且不会在字节码中进行。该信息在运行时不是必需的,因此也不会存储在字节码中。



JVM会以相同的方式对待最终局部变量和非最终局部变量。 / p>

Where is information such as if a local variable is "final" stored in Java bytecode? I know that for fields (global variables) and methods these are found in the access flag bits, but cannot seem to find the equivalent in the local variable table.

I am interested in this question as I am using BCEL to check if a local variable is final, and have found the equivalent for fields, methods and classes in the class AccessFlags.

Thanks in advance.

解决方案

The finality of local variables is checked by the compiler and doesn't make it to the bytecode. This information isn't required at runtime, and hence isn't stored in the bytecode.

The JVM treats final and non-final local variables in the same way.

这篇关于如何从Java字节码中判断局部变量是否为“最终”? (与BCEL有关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆