Generating data classes in Java

Bertil Muth on November 08, 2018

Kotlin has a concise syntax to declare data classes: data class User(val name: String, val age: Int) The equivalent Java syntax is verbose... [Read Full]
markdown guide

Pretty nice! This could be a good approach when designing large systems with lots of models.I actually had a similar idea in the past, because I needed to generate getters/setters for about 100+ POJOs.

Right now I'm just mixing Kotlin and Java, so I benefit from Kotlin's Data classes whilst using Java for the most parts.


Yes, there are many ways to reach a goal!:-) As you said, my approach is especially useful with big numbers of classes, and if you have to customize the generated classes further.


I am glad you found it interesting - I recently read the article you referenced, I didn’t know about Java 12‘s record before. It looks like a spitting image of Kotlin.

Code generation is useful beyond it, of course, it was just a simple example.


We weren't promised that Java 12 would have Records, it's something they are looking at though, if not in Java 12 then in Java 13+. For now, we could use your solution :).

code of conduct - report abuse