HashSet.contains not working as expected?
I have a HashSet<Face>. Here's face:
If I create "idential" faces (the texCoords and vertex order aren't same, but have same vertices), Face.equals returns expected value. However, if I do that for a HashSet, it doesn't work. An ArrayList works fine, but I need a Set. What can I do to fix?
4 Replies
⌛
This post has been reserved for your question.
Hey @The Typhothanian! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
you implement the hashCode properly
this ^ is the implementation of Arrays.hashCode
the hash code you get depends on which element is where
your equals sorts those elements (bad idea), so the equals is functionally different to hashCode
-> you broke the general contact between those two
-> Hash-optimized collections or similar things will behave wonky
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.