- class Point
- {
- int x;
- int y;
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + x;
- result = prime * result + y;
- return result;
复制代码 那个31是怎么来的?魔法数字吗? 为什么要么定义hashcode?
|
|