JavaBeans Convention


#1

I have a Kotlin class that I want to use with standard Java and JPA. There the JavaBeans convention is expected. The getters and setters are generated for me, but for boolean values I have to do this workaround to get isMarked() and then I have an extraneous getMarked() lying around.

interface Marked {
    var marked: Boolean

    // need to do this to get "is"-type getter for a boolean
    fun isMarked(): Boolean {
        return marked
    }
}

// A JPA class implemented in Kotlin
    @Entity
    class Animal : Marked {
        @Id 
        var id: Long = 0
        override var marked = false
    }

// A Java class to test things
public class Test {

public static void main(String[] args) {
    Animal animal = new Animal();
    // following shows the automatic getters we get 
    // from the kotlin class
    animal.getMarked();  // redundant, undesired
    animal.isMarked();   // desired and required by JPA etc.
}

}

Should Kotlin getters for booleans not be conformant with the JavaBeans spec, or am I missing something?


#2

if you rename the property to isMarked, the getter will have the correct name.