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
Post a Comment