Does Kotlin yet have a way to require that implementors of an interface method call super?
c
Casey Kulm
02/27/2018, 5:50 PM
interfaces don’t have any idea of inheritance so super wouldn’t mean anything in Kotlin or Java
b
Ben Piatt
02/27/2018, 6:03 PM
I disagree, interfaces can inherit from one another. I’m actively doing so in a project of mine
I’m using interface inheritance to enforce composition at the class level
And because my classes are parcelable, I allow the writeToParcel method in each interface to call its super to add its own members to the parcel
That’s one use case
c
Casey Kulm
02/27/2018, 8:43 PM
Interfaces can extend one another, but not inherit. There is nothing to inherit from an interface. Inheritance is an OOP concept, and interfaces are not Objects.
Rather than forcing a child class method to ask it’s parent method to do work, you pass in a “CommonFoo” class instance to a “SpecificFoo” classes constructor, and allow the “SpecificFoo” class to add additional info to that method