| | |
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 |
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.
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.
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.
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.
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.
Re: Why there is no "local static variable" in JAVA is any alternate available for that
0
#4 Oct 10th, 2007
![]() |
Similar Threads
- non-static and variable errors (Java)
- static variable (C)
- about static variable (Java)
Other Threads in the Java Forum
- Previous Thread: Help incrementing time in my class
- Next Thread: refining a programme
Views: 1769 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






