Kotlin class:
class Script(@JvmField val ffield: F, @JvmField val rlist: List<R>, @JvmField val dfield: String)
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?
yole
July 24, 2017, 2:29pm
2
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.
yole
July 24, 2017, 4:34pm
4
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();
yole
July 24, 2017, 4:40pm
6
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.