Public properties get public backing field

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 xmlRootElement public 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 IllegalAnnotationExceptions Class has two properties of the same name "name" this problem is related to the following location:   at public final ....Person.getName()   at ....Person this 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 xmlRootElement import javax.xml.bind.annotation.XmlTransient as xmlTransient public 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…

This should be already fixed. Try updating to a nightly build or wait for the next milestone (coming pretty soon).

Kool! M3 coming soon... Any idea on release date?

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.

This is great. There's little need to rush it out to 1.0 before it's ready.

I'm a little curious.

What are you planning to build with it? I mean creating your own language is no small undertaking, so I’m thinking you have something in mind for it.

:slight_smile:

This message seems to be a little off topic. If this document doen't answer your question, please feel free to start a new thread on this matter.

Yes, it was hideously off-topic; my apologies.

And thanks for the link.