Jiri Bruchanov
04/24/2020, 1:20 PMJiri Bruchanov
04/24/2020, 1:20 PMopen class Test {
protected open fun test() {}
}
open class SubClassTest : Test() {
var classTest: Test = Test()
public override fun test() {
//failing because "test()" is protected in Test
//java is fine with it
classTest.test()
}
}
Jiri Bruchanov
04/24/2020, 1:21 PMdiesieben07
04/24/2020, 1:26 PMprotected
is more strict in Kotlin than in Java. It does not include "package-private" (since there is no such thing in Kotlin).
In Java you can access the test
here, because its the same package.
If Test
were in a different package than SubClassTest
this access would not be allowed from Java eitherr.Jiri Bruchanov
04/24/2020, 1:28 PMdiesieben07
04/24/2020, 1:29 PMdiesieben07
04/24/2020, 1:29 PMdiesieben07
04/24/2020, 1:30 PMJiri Bruchanov
04/24/2020, 1:31 PM