I would like to place a recursive function within a thread runnable run() method – here is an example fragment..
yt[c] = new Thread ( new Runnable() { public void run() { /* recursive function here */ } } );
Is their any way to implement this within the run() method? Effectively embedding a method within a method (I’m assuming a recursive function has to be implemented as a method)?
As a trivial example say how would I implement n! within a run() method (recursively not iterated)? I am puzzled.
Many thanks.
Well, you won’t embed the method in the
runmethod itself. Rather just add one more method in addition torunand call it: –Since with
new Runnable() { }, you are just creating a anonymous class implementing theRunnableinterface, so, there is no one stopping you from adding your own extra method. And probably you can also make itprivate, as you won’t be using it from outside.