Hi I have a HashSet like the following in a class called Memory:
Set<Idea> ideas = new HashSet<Idea>();
The generic type “Idea” is another class I wrote that has hashcode() and equals() overriden.
I want to be able to get(and not remove) an Idea object in the HashSet ideas, then change it by adding something to it possibly changing it’s hashcode() return value. I heard that this is would not work but no one explained why. I was wondering if someone could tell me how I can do this most efficiently.
If you want to perform a lookup, you should be using a Map. If you want to change the key (or an element of a Set) you have to remove it first and add it again. For this reason your key should only have immutable fields.