我有一个返回字符串值的函数。要生成此值,函数使用Timer
,而Timer
生成提及的值。如何从Timer
返回生成的值?
String str = GenerateStr();
和
public String GenerateStr() {
final Timer timer = new Timer();
final TimerTask task = new TimerTask() {
@Override
public void run() {
//Do Something
String myStr = "something" //<==I want to return this value
}
};
timer.schedule(0, 1000);
return "???" //What can I return?!
}