Created
January 29, 2015 15:48
-
-
Save orekyuu/580b493065068270e2b0 to your computer and use it in GitHub Desktop.
2回目の出力でfalseになる理由が知りたい
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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