-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
改变集合中对象属性,依然可以remove掉 #74
Comments
我用的Eclipse也可以remove掉,求解答 |
重写了equals 和hashCode方法吗? hashset的内部实现用的是hashmap. hashmap判定是 通过 是否是同一个对象 && hashcode相等. 或者 equals方法相等. |
这个Person类应该是重写了hashCode方法的,比如最简单的,
这样在p3修改了age之后对于hashset来说就变成另一个元素了,当然remove不掉,再添加时也会认为是另一个元素所以size会变成4 |
remove 对象的地址, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我demo试了一个,改变集合中对象的属性,然后再remove这个元素,是可以remove掉得啊,打印集合的size,减一了啊
The text was updated successfully, but these errors were encountered: