| Author |
Method Local Inner Class Question
|
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Hi, I did not understand the following sentence from Kathy Sierra Book. A method-local inner class cannot use variables declared within the method (including parameters) unless those variables are marked final. I wrote a sample code as below. According to the above sentence from kb book, I made variable 'a' final but I cannot access it. I can only access the variable 'j' if it's final, but then again, I cannot access the method someMethod222() even if it's marked final? Thanks. [ September 19, 2008: Message edited by: Arjun Reddy ]
|
Be Humble... Be Nice.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
Maybe because you are calling "OuterClass.this" when the "a" is a local variable, not an instance field.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
. . . and you can't usually use the keywords "this" and "super" in a static method because both keywords refer to instances.
|
 |
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Hi Campbell, Thanks for replying. Can you give me a code sample of what this means exactly? A method-local inner class cannot use variables declared within the method (including parameters) unless those variables are marked final. Thanks.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Did you try.... Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Okie... it worked. Thanks Campbell and Henry  [ September 19, 2008: Message edited by: Arjun Reddy ]
|
 |
 |
|
|
subject: Method Local Inner Class Question
|
|
|