https://kotlinlang.org logo
#announcements
Title
# announcements
d

dMusicb

06/13/2019, 1:27 AM
Is it possible to have a data class that has a java class as a property? Was getting an issue when comparing two equivalent data classes. Found out there was no toEquals/toString override on the java class so it was showing the class@hash value. I added those methods to the class and I see the data classes now have the same values but it’s still failing the comparison.
g

gildor

06/13/2019, 1:42 AM
This is not a problem of data class and not really Java problem, this class just doesn’t overrider hascode/equal, so comparing by reference, so always return false for any other instance of the same class
d

dMusicb

06/13/2019, 1:46 AM
Yeah I added the override methods to the class and same issue
g

gildor

06/13/2019, 2:01 AM
how this method looks like?
d

dMusicb

06/13/2019, 2:17 AM
Yep, hash code used some util instead though so perhaps that is causing a difference, will check the actual hashcode values
g

gildor

06/13/2019, 2:17 AM
just check those classes first, create instance and compare
data class just compare by delegating to field class instance