Live data from Hacker News

Java's records, Lombok's data, and Kotlin's data classes

nipafx.dev

11–20 of 294 posts

Re: Java's records, Lombok's data, and Kotlin's data classes

#11
post #5

They are still classes, still live on the heap and still need to be garbage collected. Compare with value types that live on the stack in other languages such as Swift, Go and Julia.

Isn’t the point that Record classes will be able to be upgraded to value types easily once Valhalla is done? Or am I missing something

Re: Java's records, Lombok's data, and Kotlin's data classes

#15
Kotlin data classes can be used with the JPA contrary to Java records. It's good to encourage immutability, but it is often a misfit and isn't the role of a "data class", they could have added a separate class qualifier immutable that would have been a better separation of concerns, here it's ad-hoc. Kotlin is enabling such immutable support thanks to Java records ironically https://kotlinlang.org/docs/jvm-records.html#declare-records...

Note however that an upcoming version of Java will get first class ergonomic support for manipulating immutable data: https://github.com/openjdk/amber-docs/blob/master/eg-drafts/...

There is also https://github.com/hrldcpr/pcollections

Re: Java's records, Lombok's data, and Kotlin's data classes

#17
I think the article is misleading in the list of advantages over Kotlin's Data Classes.

1. Destructuring - available in Kotlin

2. Copy with change - available in Kotlin

3. Serialization - not sure why Kotlin data class would not be serializable

4. Boilerplate - Kotlin takes care of equals and hashCode

Huge disadvantage that matters to me is that record fields cannot be mutated. It makes the records much less useful.

Re: Java's records, Lombok's data, and Kotlin's data classes

#18
post #9

Who is arguing otherwise? It's assumed that when a language adds a new feature that's historically been provided by libraries, it's probably better optimized. CompletableFutures, Streams, Date/Time. For many they've replaced libraries filling the gaps. But not all of us can use JDK 14, and will continue to use Lombok if we're writing in Java.

Work on a Grails app; only boots on up to 11 ATM. BUT, the hot reload only works with 8... So while the app runs on 11, most development occurs on 8 still.

Lombok JustWorks™. You forget it's there until you setup a new dev environment and forget to setup the annotation processor in IntelliJ.

Post reply on HN