Kotlin has a concise syntax to declare data classes:
data class User(val name: String, val age: Int)
Enter fullscreen mode
Exi...
For further actions, you may consider blocking this person and/or reporting abuse
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 will continue to let IntelliJ do it for me...
Haha, sure.
I got some useful ideas from your post. Thank you for that. IT seems that Java 12 introduces a record concept. See
Interesting JDK 12 features to watch out for.
Lemuel Ogbunude
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 :).
Good to know, thanks.
I prefer Lombok projectlombok.org/features/Data