How to detect recursion in Java methods -


how can check inside method body, if method, call, calls in turn method back.

// method, control public void mymethod() {      if( stackcontainsmymethod() ) {         throw new runtimeexception("do not call me");      }       ...      handler(); }  // else implements protected abstract void handler(); 

the handler must not call mymethod(). want enforce @ runtime. can simple approach?

regards.

if want @ current stack trace , check yourself:

stacktraceelement[] trace = thread.currentthread().getstacktrace();  for(int i=0; < trace.length; i++) {     //look , exit } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -