作者:GRIROR格雷尔 | 来源:互联网 | 2023-05-19 18:48
HiIhaveaHashSetlikethefollowinginaclasscalledMemory:嗨,我在一个名为Memory的类中有如下的HashSet:Set&
Hi I have a HashSet like the following in a class called Memory:
嗨,我在一个名为Memory的类中有如下的HashSet:
Set ideas = new HashSet();
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.
泛型类型“Idea”是我编写的另一个类,它具有hashcode()和equals()覆盖。我希望能够在HashSet中获取(而不是删除)一个Idea对象,然后通过添加一些东西来改变它,可能会改变它的hashcode()返回值。我听说这不行,但没有人解释原因。我想知道是否有人能告诉我如何才能最有效地做到这一点。
3 个解决方案