Updated to the latest stable version of intellij a...
# intellij
r
Updated to the latest stable version of intellij and I've been getting suggestions to change objects to data objects when they're subclassing a sealed class, What's the difference between the object and data object Or they're the same?
c
data objects are objects with better
toString()
implementations, saving you from having to add that yourself.
r
Oh okay. Thanks
s
Another important thing is that `data object`s have overriden
equals
and
toString
. This may be important in the use cases when they are created using reflection bypassing their singleton nature. I once had a situation where jackson was creating
object
using reflection on json deserialization. That object was subclassing sealed interface and out of nowhere my exhaustive
when
expression started throwing
NoWhenBranchMatchedException
because object created by jackson wasn't the same instance as the one which should be the singleton in memory. `data object`s ensure such issues would not happen
❤️ 2