Loney Chou
09/29/2023, 3:18 AMxoangon
09/29/2023, 8:13 AMprotected
nor private
are allowed in interfaces, and that's something that makes sense.
An interface is a contract that doesn't get into implementation details. Both private
and protected
functions are part of an implementation.
I recommend you read this Medium post about interfacesRonny Bräunlich
09/29/2023, 8:52 AMinterface Foo {
val inner: OtherFoo
fun doSomething() {
println("foo")
inner.doSomething()
}
}
Loney Chou
09/29/2023, 9:30 AMprotected
nor private
are allowed in interfaces.
>
private
is allowed in interfaces. The only reason I saw so far is "you can share logic for default functions", but with top level functions (even in Java you could make another util class), it makes no sense to have them inside interfaces (on the language level).xoangon
09/29/2023, 11:33 AMprivate
functions in interfaces. The correct statement would be:
> You can’t declare private
or protected
abstract methods/accessors in an interface