我希望在指定的时间安排任务startTime
,当该时间到来时,我希望它运行一个method rrun(boolean param1, Object someObj)
。
rrun()
是说,是课堂上的一种方法SomeClass
。
并且,SomeClass
再次,我有一个方法m1()
将其作为其代码的一部分:
Timer startTimer = new Timer();
startTimer.schedule(new TimerTask() {
public void run() {rrun(false, this);}
},
startTime);
为此,我得到的错误
incompatible types: <anonymous TimerTask> cannot be converted to SomeClass
我在做什么错了?
TIA。
// ==============================
编辑:
我正在使用JDK 8-最新版本
在匿名内部类内部,this
是对当前TimerTask
匿名子类(而不是封闭类)的引用。
要引用封闭类,请限定this
:
public void run() {rrun(false, SomeClass.this);}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句