Skip to content

Instantly share code, notes, and snippets.

@sangmoon
Created December 3, 2019 09:39
Show Gist options
  • Save sangmoon/c39102b43c2c3aaf8b9c9328fb2dc63b to your computer and use it in GitHub Desktop.
Save sangmoon/c39102b43c2c3aaf8b9c9328fb2dc63b to your computer and use it in GitHub Desktop.
equals hashcode map에 대한 과제
public class SKey {
private int value;
public SKey(int value) {
this.value = value;
}
@Override
public boolean equals(Object other) {
return false;
}
@Override
public int hashCode() {
return 1;
}
public static void main(String[] args) {
Map<SKey, String> map = new HashMap<>();
SKey a = new SKey(1);
SKey b = new SKey(2);
SKey c = new SKey(3);
map.put(a,"a");
map.put(b,"b");
map.put(c,"c");
// 이 때 map의 상태는?
map.size();
// 아래 호출의 return 값은?
map.get(a);
map.get(b);
map.get(c);
}
}
@sangmoon
Copy link
Author

sangmoon commented Dec 3, 2019

수도 코드라 작동안할 수도 있음..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment