How to get the unique ID of each object in Java?
•
Java
See the English answer > how to get the unique ID of an object which overrides hashcode()? 9
It should be object anyway The hashcode () method is a unique ID for each object
However, it can be overridden anyway, so it is not guaranteed to be unique or unique for each object instance
If I want to create an "ObjectSet", how can I get the guaranteed unique ID of each instance of an object?
I just found this: which answer
How to get the unique ID of an object which overrides hashCode()?
Solution
java. lang.System. identityHashCode(OBJ); If you really need it and understand the impact, I will do this for you It obtains the identity hash code, even if the method providing the hash code has been overwritten
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码