• Post Reply Bookmark Topic Watch Topic
  • New Topic

inner annonymous class accessing this  RSS feed

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this anonymous class


this statement causes compiler error it says no enclosing instance of type GoApprovalCommentsPanel is accessible in scope?

Why cant I access this in side instance method when its annonymous inner class?
 
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, we're only seeing some of the code here. But I guess this is the part that's not compiling?

You don't appear to be inside the class GoApprovalCommentsPanel; rather, you are inside an anonymous subclass of GoApprovalCommentsPanel. Which is not the same thing. I suggest you replace "GoApprovalCommentsPanel.this" with simply "this", since the annonymous subclass is the immediately enclosing class, and "this" will resolve to that class, absent any other qualifier.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam bartl wrote:I have this anonymous class...

Sam,

Please DontWriteLongLines (←click). It makes your threads very hard to read. I've broken them up for you this time, but please read the UseCodeTags page again thoroughly.

Thanks.

Winston

PS: I think you could make your code a bit more readable by breaking the logic up a bit too. For example:You may also find it better for debugging.

You don't get extra points for cramming as much logic as humanly possible into a single line.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!