logo
down
shadow

override and implement fn from class in interface


override and implement fn from class in interface

Content Index :

override and implement fn from class in interface
Tag : kotlin , By : fstender
Date : December 05 2020, 12:18 PM

this one helps. There isn't a great way to do this other than using maybe an annotation processor to add the missing override at compile time (by adding an annotation to the interface that you detect and you generate the overrides in the implementation class). This would work, but may be biting off more than you want to, and is likely out of scope of an answer here on Stack Overflow (seek "how to write an annotation processor for Java or Kotlin" and "KAPT" for the one engine that supports Kotlin processors).
Back to your code and why it will not work as-is:
interface SingletonObjectTrait {
    fun asString(): String = this.javaClass.simpleName
}

open class SomeEventLogic {}
interface SomeEventType {}

object MyEvent: SomeEventLogic(), SomeEventType, SingletonObjectTrait {
    override fun toString(): String = asString() // hope they don't forget to call this!
}

Comments