I have a value class that holds a ByteArray, i wan...
# getting-started
e
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
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
Don't think i need it. Was apart of a bug we found
k
if (other == null || other !is ContentID) return false
can be shortened to
if (other !is ContentID) return false
Also, shouldn't it be
return byeArray.contentEquals(other.byeArray)
instead of
other.contentID
?
e
I shorten the example to show it was a bytearray. so it's a typo