Reputation: 3460
I'm learning Java right now, I have timer inside one of my functions like so:
public class SomeClass {
private Timer timer = new Timer();
private void someFunction() {
timer.schedule(new TimerTask() {
public void run() {
// here lies the problem
}
},
1000);
}
}
What I want to do is call another function someOtherFunction(SomeClass c)
that takes as an argument an instance of SomeClass
. Outside of the timer, I could simply say someOtherFunction(this)
, but inside the timer that doesn't work since this
is a TimerTask
.
What can I do to get the instance of SomeClass
inside my timer?
Upvotes: 2
Views: 387
Reputation: 285405
Just use SomeClass.this
to get the outer class instance inside of the inner class.
Upvotes: 5