Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin, JPA and boolean fields

Tags:

jpa

kotlin

I'm starting to introduce kotlin in our project and I'm converting some entities to kotlin as part as a bigger refactor.

My entity had a boolean active property:

private boolean active = true;

public boolean isActive() {
    return active;
}

public void setActive(final boolean active) {
    this.active = active;
}    

Now in kotlin this should be:

var isActive: Boolean = true

The problem is that this way I have to refactor existing queries, not a big deal, but I was expecting a smoother transition.

I can do something like:

var active: Boolean = true

val isActive: Boolean
    get()= active

But it doesn't feel right. What would be the best way?

like image 705
cocorossello Avatar asked Mar 09 '23 01:03

cocorossello


1 Answers

You can rename the getter like so

@get:JvmName("isActive")
var active: Boolean = true
like image 185
Ruckus T-Boom Avatar answered Mar 10 '23 16:03

Ruckus T-Boom