Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Why static storage allocation in java not support the recursive procedures?
|
Posted: Mar 17, 2002 1:35 PM
|
|
What? If you are using static variables in recursive methods in Java, C++ or any other language, the effect will be the same. Usually, you don't use static variables in recursion, unless it is to keep track of a node count or something like that (even then it is a bad idea, especially in a multi-threaded program; if your recursive method it executed twice at the same time, the static variable becomes junk; this is even true for a class variable -- you will need to add synchornization to keep it clean). If you expect a static variable to be a fresh new instance in each call, then you don't understand static variables. There is a post just a few days ago with a little demo program that can help you understand the difference between static variables (some call them "class variables") and instance variables. Usually, recursion relies on the fact that a new set of local variables is created for each method call, however.
It is really a shame that the word "static" has stuck since the C days. I think the abstractness of this word adds a lot to the confusion people have with it.
|
|