2

我现在正在学习 Java,我的一个函数中有一个计时器,如下所示:

public class SomeClass {
    private Timer timer = new Timer();

    private void someFunction() {
        timer.schedule(new TimerTask() {
            public void run() {
               // here lies the problem
            }
        },
        1000);
    }
}

我想要做的是调用另一个函数someOtherFunction(SomeClass c),该函数将SomeClass. 在计时器之外,我可以简单地说someOtherFunction(this),但在计时器内部不起作用,因为thisTimerTask.

我该怎么做才能SomeClass在我的计时器中获取实例?

4

1 回答 1

5

只需用于SomeClass.this获取内部类内部的外部类实例。

于 2013-11-01T03:42:10.337 回答