Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annonymous Inner class doesnt use final var

 
Paul Salerno
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I wanted to be sure that in this case it is not necessary for items to be declared final, since its being used w/in the annonymous inner class. Also wanted to be sure that if this were the case that this annonymous inner class were inside a method, then and only then, would the methods local var and parameter need to be final.
Thanks guys
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your example looks fine.
You only need to worry about final local variables in the method that contains an inner class, anonymous or not. And remember that method arguments are local variables as well. But any local variables you create *inside* your inner class are fine and don't need final.
Rob
 
Paul Salerno
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks G its all clear to me now, appreciate that. Issue closed
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I dunno. It seems like issues never get closed around here
Rob :roll:
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Ross:
Oh, I dunno. It seems like issues never get closed around here
Rob :roll:

What do you mean ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic