When creating a public property using the public var ... declaration, not only the property accessor methods (get... and set...) are becoming public in the generated byte code, but also the backing field which is definitely not what I would expect and which makes the use of a few frameworks impossible.
My concrete problem is the usage of XML-binding via JAXB. Declaring the following class
import javax.xml.bind.annotation.XmlRootElement as xmlRootElementpublic xmlRootElement class Person { public var name: String = ""}
leads to the following runtime exception:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptionsClass has two properties of the same name "name"this problem is related to the following location: at public final ....Person.getName() at ....Personthis problem is related to the following location: at public ...Person.name at ....Person
The IntelliJ Kotlin plug-in shows the following generated code:
// access flags 0x1 public Ljava/lang/String; name // access flags 0x11 public final getName()Ljava/lang/String; @Ljet/runtime/typeinfo/JetMethod;(flags=1, propertyType="Ljava/lang/String;") ALOAD 0 GETFIELD com/gettingmobile/upodservices/domain/Person.name : Ljava/lang/String; ARETURN MAXSTACK = -1 MAXLOCALS = -1 // access flags 0x11 public final setName(Ljava/lang/String;)V @Ljet/runtime/typeinfo/JetMethod;(flags=1, propertyType="Ljava/lang/String;") ALOAD 0 ALOAD 1 PUTFIELD com/gettingmobile/upodservices/domain/Person.name : Ljava/lang/String; RETURN MAXSTACK = -1 MAXLOCALS = -1
Until this is fixed you can use the following workaround to use JAXB:
import javax.xml.bind.annotation.XmlRootElement as xmlRootElementimport javax.xml.bind.annotation.XmlTransient as xmlTransientpublic xmlRootElement class Person { public xmlTransient var name: String = ""}
This works because the @XmlTransient annotation is only added to the backing field, but not to the getter-method…
We refrain from putting up a release date, but the plan is to roll Kotlin out in production at JetBrains in a few months. This will not be a release, as teh design of the language will be subject to many changes as we go using it in a real-life setting.