Inline methods in interfaces


#1

Currently it’s not possible to have inline methods in interfaces, because virtual methods can’t be inline and interface methods can’t be final.

It does seem totally reasonable to have inline methods in interfaces however. I personally never subscribed to the belief that Java’s default methods had to be used to extend legacy interfaces only (that was the intent however).

I know one can easily define an extension method to do the same thing, but the extension method has to be imported separately or through a wildcard, and I’d like to avoid that.


#2

As long as Kotlin targets the 1.6 class format this may not be possible or have ugly workarounds. The best implementation would be as extension functions (inline functions still exist in the class file), but those are only available in 1.8. Of course a workaround could be to define them on some sort of “companion” class that would automatically be resolved without imports being necessary (in Kotlin, Java would require it).


#3

Has the situation changed now that we can target 1.8 with Kotlin?


#4

While this can be done with companion objects, the code would look ugly. Is it possible to make the inline interface default methods be generated as companion object methods automatically? While this may have confusion with Java interop (because Java cannot call the methods on the interface directly), is it possible to make the inline function only callable from Kotlin?