Kotlin val not reachable form Java


Kotlin class:

But when I instance a ScriptKt class from java, the fields for f, rlist and d aren’t available. I was expecting something like:

ScriptKt script = new ScriptKt();
script.getFfield() // Why isn't this here?  Compile error and doesn't show up in code complete.

What am I doing wrong?


You’ve applied the @JvmField annotation to the properties. A property with that annotation is compiled directly to a Java field, and the corresponding getter and setter are not generated. You can access such a property as script.ffield.


That isn’t available either.


ScriptKt is the facade class for top-level declarations declared in script.kt. A Kotlin class named Script is referenced from Java as simply Script.


I’m confused. So should I reference my kotlin “Script.kt” class from Java as “Script” like:

Script script = new Script(); 


Script.kt is not a class, it’s the name of a file. A class called Script should be referenced from Java as new Script(), indeed.


That worked. Thank you!