This message was deleted.
# stdlib
s
This message was deleted.
👍 7
b
I like the idea, but I’m not sure if this will be used. In my experience 95% of
hashCode
functions I use are from data classes. Also with a good IDE you will just auto generate the
hashCode
function in any case.
s
Any particular reason you dont use
Objects.hash
?
k
Overhead, it creates a temporary array.
👍 1
s
I would be surprised if varargs arent heavily optimised on both the jvm and js
In any case.. I would heavily prefer a global
hash
with agressive compiler inline and unroll than another
Any?
extension. Just my two cents. Would be shorter to write also
Your implemention would also box any primitives I think
Ah sorry. It was collapsed here.
z
One more argument for doing this is that data classes are effectively useless for library APIs: https://jakewharton.com/public-api-challenges-in-kotlin/
b
You can work around the problem with the
copy
function by providing a custom copy function that calls the generated one, you just need to annotate it with
@Deprecated("", level = DeprecationLevel.HIDDEN)
. I don’t know a workaround for
componentN
except for only adding new properties to the end. That said, I don’t like the fact that kotlin adds
componentN
functions to all data classes automatically. Since they aren’t named, they just pose to much of a risk IMO. Especially when the data class is provided by a library.