Kotlin override equals in value class
I am writing a Fraction class in Kotlin using a value class and a Long internally to avoid heap allocation, like this:
@JvmInline
value class Fraction(private val value: Long) : Comparable {
val numerator: Int
get() = (value shr 32).toInt() // Get the numerator (higher bits)
val denominator: Int
get() = value.toInt() // Get the denominator (lower bits)
...
override fun equals(other: Any?): Boolean {
return super.equals(other)
}...