Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between an object and a data object?

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?

like image 919
fredoverflow Avatar asked Oct 24 '25 02:10

fredoverflow


1 Answers

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.

like image 133
Alexander Udalov Avatar answered Oct 26 '25 20:10

Alexander Udalov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!