DEV Community

Kotlin: Removing POJO Boilerplate

Steve Crow on February 24, 2018

Kotlin is very quickly becoming one of my all-time favorite languages to play with. It is a JVM language that offers static typing, built-in null s...
Collapse
 
stealthmusic profile image
Jan Wedel

Although I like Kotlin because of great features like Coroutines, Pojos are not the key feature to me. This has been solved with Lombok in Java:

@Data
class Person {
    private String name;
    private int age;
}

It's not one line, but concise enough to me.

Collapse
 
erikthered profile image
Erik Nelson

I will agree that there are definitely more compelling features in Kotlin than data classes. However, it feels cleaner being built into the language versus having to include Lombok's annotation processor.

Collapse
 
serhuz profile image
Sergei Munovarov • Edited

Why not just move name and age to the class body? This way you get a no-arg constructor by default. And you can use with or apply elsewhere in code when instantiating Person.