Internal methods in interface

I like to see the option to add internal methods to an internal interface.


internal interface MyInterface{
    internal fun myFun()
class Test : MyInterface{
   override internal fun myFun() = Unit

Internal interface cannot expose public methods (interface itself is not public).

I updated my suggestion.
(the next time I try to be clear from the beginning)

The question here is can you inherit from an internal interface (what about classes) and should you? At the same time I have similar wishes (I’d like to have protected members in interfaces - with default methods you almost get multiple inheritance).

The minimum requirements to fullfill my use-case:

  • An interface/abstract class with an abstract internal function needs to be internal
    (Cross-module can be explored later on)
  • An interface can be inherited from by non-abstract classes (from inside the same module)

later on this can be expanded to:

  • An interface can be inherited by other internal interfaces/abstract classes (with the same rules)

followed by:

  • An interface can be implemented by public interfaces/abstract classes as long as it provides an (final?) implementation for the abstract internal functions.

and, maybe later explore cross-module functions.

(I don’t know anything about the compiler side, so I just did it based upon restrictions)

Just dropping this for others who stumbled upon here looking for the same functionality.

This feature is tracked here: (vote if your looking for the same functionality)

Also, this comment about sealed interfaces in KT-22268:

An important addition to this request that had been recently realized is that sealed interface shall support internal members. This would allow library API design and evolution without ugly hacks.

1 Like