Closed TheMode closed 2 years ago
Good question.
SA: Yes, ClassIndex detects the unlikely collision and will exit with a clear error without starting to mess up with the user application data.
LA: you went straight on to the core of the library where (one of) the magic happens. Java doesn't provide a safe unique id for a Class type - as far as I know, and I'm open to discussion and very happy if someone will come up with a different approach. That means you should always rely on the equals() check to prevent collisions. Here is a trade-off, implement lightning-fast (around 1ns) checking to detect a class type with a 99.999999999% success rate or have the worst performance just to avoid a very unlikely collision that could occur much less frequently than a common OutOfMemory error.
I will not close this issue just yet to leave the discussion open for a while.
Updated implementation:
I may be wrong, but
ClassIndex
does not seem to handleSystem.identityHashCode
returning the same for two distinct classes, as collision detection is only implemented based on the even smallerhashBits
field. Which is an unlikely scenario, but not impossible.