https://kotlinlang.org logo
Title
z

zceejkr

10/28/2019, 12:13 PM
One more question, would it be possible to override the equals and hashcode methods on the ByteArray from the Kotlin standard library, to check for value equality rather then referential equality? Extension methods seem to be shadowed by member declarations, but is there some other way of doing that or do I have to manually do this in all data classes that contain ByteArrays?
k

karelpeeters

10/28/2019, 12:23 PM
No, there's no real solution for arrays. You could use a list or create your own wrapper class that does implement
equals
as you want.
z

zceejkr

10/28/2019, 12:24 PM
I see, thank you.
k

kevinherron

10/28/2019, 3:45 PM
use
ByteArray.contentEquals
instead?
k

karelpeeters

10/28/2019, 4:28 PM
But that doesn't help when using a
ByteArray
as a data class property.
k

kevinherron

10/28/2019, 4:37 PM
no, you have to override hashcode and equals for the dataclass still
annoying indeed
i missed the last part of your question where you mention data classes. sorry.
i override and use
contentEquals
where appropriate