package com.java13.myjava;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
public class Hashcodetest {
@Test
public void testhash(){
Set<Dog> set=new HashSet<Dog>();
Dog d =new Dog(20,40);
//如果有就的添加不进去
set.add(d);
set.add(d);
set.add(new Dog(20,40));
System.out.println(set.size());
}
}
class Dog{
int x=1;
public int weight;
public int height;
//alt+shift+S 快捷生成构造函数
public Dog(){
super();
}
public Dog(int weight, int height){
super();
this.height=height;
this.weight=weight;
}
public int hashCode(){
return height+weight;
}
public boolean equals(Object obj){
return false;
}
}