import java.util.HashMap;
public class Main {
static class BlockState {
int blockValue;
BlockState(int newValue) {
blockValue = newValue;
}
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
BlockState b = (BlockState) o;
return (blockValue == b.blockValue);
}
@Override
public int hashCode() {
return blockValue;
}
}
public static void main(String[] args) {
HashMap<BlockState, Boolean> visited = new HashMap<>();
BlockState b1 = new BlockState(1);
visited.put(b1, true);
BlockState b2 = new BlockState(1);
if(visited.containsKey(b2)) {
//you expect this to be executed
System.out.println("It contains");
} else {
//but actually this will be executed ??!
System.out.println("It does not contain");
}
}
}