Search code examples
javabytecodebcel

How can one tell if a local variable is 'final' from Java bytecode? (Related to BCEL)


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.


Solution

  • 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.