A Java record is a Kotlin data class? Right? <http...
# feed
a
A Java record is a Kotlin data class? Right? https://blogs.oracle.com/javamagazine/records-come-to-java
a
Not exactly, but they are close
As far as I remember, records are partially done on VM level
👍 2
t
From what I read from the docs,
data class
and Java records have the same goal, but differ on the implementation : - Records share a base class
java.lang.Record
-
toString
,
hashCode
... have a JVM intrinsic with
invokeDynamic
, resulting in smaller and more efficient bytecode (data classes may benefit from that in the future) - Data classes are fully generated at compile time and are platform-agnostic
👍 6
b
Jake Wharton explains it a lot on kotlinconf -

https://youtu.be/te3OU9fxC8U?t=1100

👍 8
a
Thank you all for your feedback
e
Is not a problem to kotlin at all, but a problem to lombok 🙂
m
If it gets added, I''m sure the maintainer of Lombok will be happy. One less feature to have to support/develop/maintain. But I've rarely had to deal with Lombok, and never chose to use it.
👍 2
a
Lombok is made for old Java versions. Records are only preview in JDK14 and adoption rate will be minuscule for a long time still.
n
Another difference to Kotlin data classes is that fields of Java records are always
val
(i.e. no setters)
n
Java records don’t seem to have the convenient copy method that Kotlin data classes have.