How do I expose a protected parent member as public for an interface?


The following code does not compile:

interface It {
    fun f()
    val p: Int

open class Base {
    protected fun f() {}
    protected val p = 18

class Derived: Base(), It {


The error is “Cannot infer visibility for ‘fun f(): Unit’. Please specify it explicitly”, same for p.

Is it possible to expose the protected fields in Base as public in Derived so that it can implement the interface?


No. Common protected fun/val and exposed fun/val in the interface must have different names. If you try to make something like “default interface methods” you can do it right in interface (for property you can define get() method) or inherit Base from It and dont forget override modifiers. In first case you don’t need Base. In second case Derived inherits just from Base. First or second case depends of your target platform (for example jdk version < 1.8 not able to define default interface methods).


Ok, thank you for the detailed answer!