posted 18 years ago
Hello,
According to the K&B book (chapter 8), a Method-Local Inner Class cannot use variables declared within the method unless those variables are marked final.
This is because the Method-Local Inner Class object might live longer on the heap than the local variable in the method would live on the stack.
-
This is all fine and dandy, but what makes a final variable so different?
Sure - the keyword final makes it impossible to reinitialize that variable once it has been initialized - but doesn't a final variable also live on the stack and therefore might still have a shorter life than the Method-Local Inner Class object?
Thanks,
Richard
"...it takes all the running you can do to keep in the same place. <br />If you want to get somewhere else, you must run at least twice as fast as that!" <br />~ Through the Looking-Glass