The Artima Developer Community
Sponsored Link

Java Answers Forum
Why static storage allocation in java not support the recursive procedures?

1 reply on 1 page. Most recent reply: Mar 17, 2002 1:35 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Bob

Posts: 4
Nickname: turshu
Registered: Mar, 2002

Why static storage allocation in java not support the recursive procedures? Posted: Mar 17, 2002 11:07 AM
Reply to this message Reply
Advertisement
Why is the static storage allocation in Java not able to support the implamentation of recursive procedures?

Thank you


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
Reply to this message Reply
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.

Flat View: This topic has 1 reply on 1 page
Topic: Java Telephony Previous Topic   Next Topic Topic: What is the use of the Canvas class?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use