public final class IDNumber { private final int id; public IDNumber(int id) { this.id = id; } public boolean equals(Object object) { if (object == this) { return true; } else if (object instanceof IDNumber && this.id == ((IDNumber)object).id) { return true; } return false; } public static void main(String[] args) { Map map = new HashMap(); Object initialKey = new IDNumber(123); map.put(initialKey, "Oka"); Object findKey = new IDNumber(123); // (1) "true"が表示される System.out.println(findKey.equals(initialKey)); // (2) "null"が表示される System.out.println(map.get(findKey)); } }