Skip to content
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

Java期末试题答案错误 #252

Open
Light-Towers opened this issue Sep 20, 2022 · 3 comments
Open

Java期末试题答案错误 #252

Light-Towers opened this issue Sep 20, 2022 · 3 comments

Comments

@Light-Towers
Copy link

期末试题第二题

image
我实验得到的结果:HashSet的size是2。


原因:

  1. public boolean equals(Value v) { return v.i == i; } 并不是对父类equals(Object var1)的重写。

重写部分规则:

  • 参数列表与被重写方法的参数列表必须完全相同。
  • 返回类型与被重写方法的返回类型可以不相同,但是必须是父类返回值的派生类(java5 及更早版本返回类型要一样,java7 及更高版本可以不同)。
  1. 需要重写equals(Object var1) 和 hashCode() 方法,得到的HashSet的size值才是1
@ngcs-mp
Copy link

ngcs-mp commented Sep 20, 2022 via email

@gzldcc
Copy link

gzldcc commented Sep 20, 2022 via email

@qfblqyj
Copy link

qfblqyj commented Sep 20, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants