可变的hashmap键是一种危险的做法吗?
class Key { int a; //mutable field int b; //mutable field public int hashcode() return foo(a, b); // setters setA and setB omitted for brevity }
HashMap<Key, Value> map = new HashMap<Key, Value>(); Key key1 = new Key(0, 0); map.put(key1, value1); // value1 is an instance of Value key1.setA(5); key1.setB(10);
map.get(key1)
扬帆大鱼
莫回无
RISEBY