• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final Local Variable

 
Ovidiu Mura
Greenhorn
Posts: 2
Android Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a local variable is devlared final, where is it stored? Stack? Heap?

For example:

class Test{

public void foo(){
final int var1 = 0; // var1 cannot be modified; where does 'var1' is stored?
}

}

Thanks in advance,
 
Stephan van Hulst
Bartender
Pie
Posts: 5893
63
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The final modifier should not affect where a variable is stored. So regardless, a local variable will still be on the stack. However, keep in mind that when you reference a final local variable from an anonymous class, a copy of the value will be stored in an "invisible" variable in the instances of that anonymous class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic