This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Final Local Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Final Local Variable" Watch "Final Local Variable" New topic
Author

Final Local Variable

Ovidiu Mura
Greenhorn

Joined: Jun 18, 2011
Posts: 2

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

Joined: Sep 20, 2010
Posts: 4087
    
  18

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.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Final Local Variable
 
It's not a secret anymore!