Essentially they are used for the same purpose, that is, they define a record . By doing so they automatically gain the main required methods, including the "access" methods for the equation fields, hash code , textual representation ( toString
) and copy.
In Scala methods of apply()
and unapply()
are also provided for case class
es.
In Kotlin, in data class
, methods are provided that help to similar to unapply()
, although less powerful, and language does not require the existence of apply()
. It also has "accessorias" Java Beans in addition to the normal ones that are available for any class in Kotlin. You can not use inheritance in records. It requires the use of var
or val
for parameters to indicate that they are fields.