Reputation: 69
I have a function defined as follows:
public Object test(int arg0){
final Time tt = new Timer();
tt.schedule(new TimerTask() {
public void run(){
Object j = anotherMethod(arg0);
//Do some checks on object j and if it fits, return this j
//I want to be able to return this object j that I get from another method
}
} , interval);
}
Basically, I want to call a function inside the run method in TimerTask and do some checking and if the function returns what I want, I want to return it in the test (method above run method). How could I do this?
Upvotes: 2
Views: 102
Reputation: 1191
I think the best to use the TimerTask Class is to let it extend the class Observable and create a method:
public void update(){
setChanged();
notifyObervers();
}
You will call the function inside the method, which detect if it is time to do something. The class which contain the method to check something, it will be registered as observer and it will implement the method of the Interface Observer. What you want to do doesn't respect the SOLID paradigma. I hope this reply will be useful for you.
Upvotes: 1