Is there a quick way in java to get the nest/recurse level?
I’m writing a function to make a list of Groups and their members. The members can be groups as well. It’s possible that we could end up with a circular set of groups/member.
I would like to stop at some arbitrary level.
I know I could just keep a variable in a higher scope or pass an incremented parameter but am wondering if there is any stack level information immediately available in Java.
I suppose even if there is, the trick would be to know at which level of nesting you would like to start counting at. So, the point may be moot, however I am still interested if there is any quick info on it.
No need for a Throwable
It won’t be fast, but you can use this: http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#getStackTrace()
You’ll have to traverse the stack in a meaninful way, but that should get you started