Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method Local Inner Class Question

 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 47278
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe because you are calling "OuterClass.this" when the "a" is a local variable, not an instance field.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47278
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . 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
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try....



Henry
 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okie... it worked. Thanks Campbell and Henry
[ September 19, 2008: Message edited by: Arjun Reddy ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic