I have a value class that holds a ByteArray, i want to use the value class as key in a map. But i can't override hash and equals. So I'm unsure if the value class will behave right and use the content. I get the error that they are reserved for future use
Copy code
override fun equals(other: Any?): Boolean {
if (other == null || other !is ContentID) return false
return byeArray.contentEquals(other.contentID)
}
override fun hashCode(): Int {
return byeArray.contentHashCode()
}
a
Adam S
08/20/2024, 1:46 PM
Are you certain you need to use a value class, could you just use a regular class instead?
There's typically little value for using a value class for non-primitive types.
plus1 1
e
Eivind
08/20/2024, 1:55 PM
Don't think i need it. Was apart of a bug we found
k
Klitos Kyriacou
08/20/2024, 2:50 PM
if (other == null || other !is ContentID) return false
can be shortened to
if (other !is ContentID) return false
Klitos Kyriacou
08/20/2024, 2:51 PM
Also, shouldn't it be
return byeArray.contentEquals(other.byeArray)
instead of
other.contentID
?
e
Eivind
08/20/2024, 9:16 PM
I shorten the example to show it was a bytearray. so it's a typo