Anyone knows how `hashCode()` is implemented by th...
# announcements
l
Anyone knows how
hashCode()
is implemented by the Kotlin compiler in a
data class
having a `fun`ction property constructor parameter? e.g.:
data class Option(val id: Int, val desc: () -> String)
m
It calls the function 🧌
l
Not possible, this would be huge flaw as this is not documented, and this could have side-effects 😛
m
To be honest I don't know, but I'd guess it is the default hashCode, i.e. takes address of the function object.
k
@louiscad why would it be a flaw? What's the difference to
data class Foo(val id: Int, val desc: Description)
where
Description
doesn't implement
hashCode()
?
m
That was a joke on my side.
desc.invoke().hashCode()
l
@kirillrakhman I said why it'd be a flaw to invoke the property function in
hashCode()
(and
equals(other: Any)
).
Any
already implements
hashCode()
, but it can be less efficient if you stick to the default implementation
k
Ok I understand. Of course, it doesn't invoke the function.