Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local inner class

 
Anne Sullivan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does a local inner class which resides inside a static method still have the "can only access local variables that is declared final" restriction?
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes whether the class is declared in a static or a non static method, it can only access local variables that are marked final..


when you compile this code it gives an error like::


Test.java:8: local variable b is accessed from within inner class; needs to be declared final
System.out.println("b = " + b);
^
1 error
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone deleted my reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic