Skip to content

Instantly share code, notes, and snippets.

@orekyuu
Created January 29, 2015 15:48
Show Gist options
  • Save orekyuu/580b493065068270e2b0 to your computer and use it in GitHub Desktop.
Save orekyuu/580b493065068270e2b0 to your computer and use it in GitHub Desktop.
2回目の出力でfalseになる理由が知りたい
public class Hoge {
private int id;
public Hoge(int i) {
id = i;
}
public boolean equals(Hoge obj) {
return obj.id == id;
}
@Override
public int hashCode() {
return id;
}
}
public class Main {
public static void main(String[] args) {
Hoge hoge = new Hoge(1);
Hoge hoge1 = new Hoge(1);
System.out.println(hoge.equals(hoge1));
System.out.println(isEqual(hoge, hoge1));
}
public static <T> boolean isEqual(Hoge hoge, T obj) {
return hoge.equals(obj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment