This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Local Variables be declared as static ?

 
Puja S
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Local variables cannot be static, but they could be final.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static members belong to the class, no to the instance objects. Static members provide services to other classes and are accessed through by of the class to wich they belong. It would not make sense to declare a static variable in the context of a local method because it just could be accessed in the same context.
 
Serkan Yazici
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think allowing static local variables in methods would have been a good idea. When you need the methods to remember their instance-independent state between calls.

I know, I know... you can still maintain this state information with static class variables but the idea is to have maximum encapsulation possible (if a member variable is only used to keep the state information about a single method, why expose it to the rest of the class).

I'm not too bothered about not having them though.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic