Re: final final final
Tim Easy wrote:
local variables declared final or not result in different bytecode
Not on my machine. Both final and non final locals generate the same
code here (jdk1.4.2_06, javac).
For example this method:
and this method:
both produce this byte code (according to javap):
void foo(int);
Code:
0: iconst_5
1: iload_1
2: imul
3: istore_2
4: getstatic #2; //Field
java/lang/System.out:Ljava/io/PrintStream;
7: iload_2
8: invokevirtual #3; //Method java/io/PrintStream.println:(I)V
11: return
Can you give an example where it does make a difference?
Bas
Please sign in to leave a comment.
Bas Leijdekkers wrote:
>>local variables declared final or not result in different bytecode
Oh wait, I see that in trivial examples with literals it does. A compile
time optimization, not very intelligent.
Bas