hyperneutrino
hyperneutrino

Reputation: 5425

Java return method from inside anonymous inner class

I have a method called play(). Inside of the class, I have a Timer (java.util.Timer), and an anonymous inner class of type TimerTask. Here is my code:

public static void play() {
    new Timer().schedule(new TimerTask() {
        public void run() {
            ...
        }, 0, 100); // Run every 10 milliseconds starting in 0 milliseconds (immediately)
}

Now the question is... I wish to return from the method play from inside the anonymous inner class (within the ...), but if I call "return", it will return from the "run" method inside the inner class. How do I return from the play method inside of the anonymous inner class?

[The title isn't very clear; I couldn't phrase it well. Please edit the title if you can think of a better title.]

Upvotes: 2

Views: 538

Answers (1)

user_4685247
user_4685247

Reputation: 2995

the function play should return immediatly, since the timer operates on another thread, thus there is no need to return outside the inner class.

Upvotes: 1

Related Questions