在Kotlin中创建一个抽象类的实例


86

我是Kotlin的新手,正在尝试在我的Android项目中使用它。我有这个代码:

public var oneTouchTimer: CountDownTimer = CountDownTimer(500, 100) {
    override fun onTick(l: Long) {

    }

    override fun onFinish() {

    }
}

并引发错误:

Cannot create an instance of an abstract class.

基本上,我正在尝试创建CountDownTimer的实例,但无法弄清楚如何将其转换为Kotlin。

这是Java中的代码:

CountDownTimer oneTouchTimer = new CountDownTimer(500, 100) {
    @Override
    public void onTick(long l) {

    }

    @Override
    public void onFinish() {

    }
};

Answers:


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.