The other day I noticed that I sometimes put data in front of objects and other times not:
object A
data object B
What's the difference between an object and a data object?
data object is a feature available since Kotlin 1.9.0. It is aimed to solve several inconsistencies in how algebraic data types are declared in Kotlin. The main behavioral difference from regular objects is that data object's toString returns the short name of the object (see KT-4107).
See more info in the official documentation or in the KEEP proposal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With