Nicolai C.
05/07/2026, 8:27 PMprotected visibility on a parent in a sealed hierarchy:
sealed class Test {
protected fun test() = Unit
}
class SubTest : Test() {
private val tests = mutableListOf<Test>()
private fun accessTestFunction() {
tests.forEach(Test::test)
}
}
In here the Test::test inside of accessTestFunction is not visible. I'd except it to be visible because SubTest is a subclass of Test, and indeed it is visible on the this scope, but not for other instances of Test. This code would work perfectly fine in Java, however for some reason it doesn't work in Kotlin. In this an intentional limitation, or a compiler bug?Huib Donkers
05/08/2026, 9:20 AMopen class A {
protected val foo = 1
}
class B : A() {
fun bar(a : A) = a.foo // Cannot access 'fun foo(): Unit': it is protected in 'A'.
fun bar(b : B) = b.foo // OK
}