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

Static Local Variable

 
Mathew Kuruvilla
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't I get a static local variable???
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew,
That's the design of the java language.
The only modifier allowed for local variable is final.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The word static means that it belongs to the whole class. It's lifetime starts when the class is loaded and dies when the class is unloaded - which for the most part means when the JVM goes down.
The word local means that it is only created when the method starts, and it dies when the method is over.

Can't be both at once, now, can it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic