0

How come in the first code block of this Runnable implementation there is no @Override annotation on run()? - run() is an abstract method:

handler = new Handler();

final Runnable r = new Runnable() {
    public void run() {
        tv.append("Hello World");
        handler.postDelayed(this, 1000);
    }
};

handler.postDelayed(r, 1000);

Compare this to my Android onCheckedChanged function which is also an abstract method:

currentlocation.setOnCheckedChangeListener(object: RadioGroup.OnCheckedChangeListener{
    override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {

    }

})

which has to have the override modifier (note: that's kotlin code but same principles apply).

How come the 2nd the 2nd code block needs to have the override keyword but the first doesn't?

Zorgan
  • 8,227
  • 23
  • 106
  • 207

1 Answers1

0

That is because the language designers decided it like that. Kotlin requires explicit override modifiers while Java does not.

See Overriding Methods in Kotlin

Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107