I am experimenting with Kotlin on Android, with Android Studio, mixing it with some existing Java code, and I've come across a problem.
I have a base class in Kotlin with a single method marked as internal:
package com.example.kotlin.hellokotlin
open class KotlinBaseClass
{
internal fun doSomething()
{
println("Done something!")
}
}
I then create a Kotlin class that extends KotlinBaseClass and calls the base class method:
package com.example.kotlin.hellokotlin
class KotlinDerivedClass : BaseClass()
{
fun doSomethingElse()
{
doSomething()
println("Done something else!")
}
}
This compiles and works fine.
If I now create a Java class that extends KotlinBaseClass instead, intended to be functionally identical to KotlinDerivedClass:
package com.example.kotlin.hellokotlin;
public class JavaDerivedClass extends KotlinBaseClass
{
public void doSomethingElse()
{
doSomething();
System.out.println("Done something else!");
}
}
I find that this class will not compile, because the method doSomething() cannot be resolved. If I remove the internal keyword from the declaration of doSomething() in KotlinBaseClass, everything works. All the classes are defined in the same package.
Is this expected behaviour? A known issue with interoperability between Java and Kotlin?