Since there's only ever one instance of an object ...
# language-proposals
k
Since there's only ever one instance of an object the default identity equals and hashcode are fine, right?
7
r
I recall some discussions on the fact that different classloaders would have their own instances of `object`s, so comparison by reference would fail, but I didn't have to deal with different classoladers myself.
k
Do you want objects from different classloaders to be equal anyway though?
r
I have no idea 🙂
d
And even the proposed solution above would yield the same result, since
Class
uses the default hashCode + equals.
👍 3
i
only ever one instance of an object
Even in a single classloader it isn't always the case, see https://youtrack.jetbrains.com/issue/KT-15378
m
Let’s just say I didn’t come up with this problem by thinking about it, but instead by fixing a bug in a Spring boot application where two “instances” (so maybe different classloaders, I’m not an expert in that field) had different hashCode and equals results. My code above did fix it for our application, so I’m not sure how the behavior differs from
object
to
Class
.
1
k
@ilya.gorbunov Is that a bug or is that the expected behavior? It's classified as a "Task" in YT, I'm not sure what that means.
i
I've originally filed that as a bug, perhaps current "task" type means it's a task to fix it 🙂
m
Your issue actually explains my situation, the object is mapped via jackson from a JSON, so it is created via reflection.