Why there is no "local static variable" in JAVA is any alternate available for that

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2006
Posts: 80
Reputation: parthiban is an unknown quantity at this point 
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

Why there is no "local static variable" in JAVA is any alternate available for that

 
0
  #1
Oct 10th, 2007
Hi all,

I learned that "local static variable" with in a function is not allowed in JAVA as in C++.

I guess it violates the rule of "static" as it's should not depend on objects but is there any alternative way avaiable to accomplish that ? (i.e scope is restricted to fuction but lilfetime untill the program ends)

Is any other reason why "local static variables" is not allowed ?

Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,515
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Why there is no "local static variable" in JAVA is any alternate available for that

 
0
  #2
Oct 10th, 2007
There is no need for a mthod to retain it's own state separate from it's instance context. If you need to maintain state in an object, make it a class level variable. If you really feel that the method MUST retain it's own separate state then you probably have a case for a separate class instead of a method.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Why there is no "local static variable" in JAVA is any alternate available for that

 
0
  #3
Oct 10th, 2007
Static is just that, by definition it's shared between all instances of a class.

A method can have final variables, which may be what you're looking for. These are however rarely used, mainly to preserve variables which are of interest to method local anonymous inner classes.
Personally in a decade of programming in Java I've rarely if ever encountered them.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 80
Reputation: parthiban is an unknown quantity at this point 
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

Re: Why there is no "local static variable" in JAVA is any alternate available for that

 
0
  #4
Oct 10th, 2007
Yes, now I understood why there is no such thing in JAVA .Thanks to Ezzaral and jwenting .
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 1769 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC