Changing an object which is used as a Map key

前端 未结 5 1486
醉话见心
醉话见心 2020-12-21 07:33

Let V be a class with a single attribute named K and its getter and setters.

What\'s supposed to happen if I do:

V v = new V();
v.setK(\"a\");
HashMa         


        
5条回答
  •  独厮守ぢ
    2020-12-21 07:53

    By calling v.setK(), you aren't changing the key in the HashMap. So you will simply have wrong information in your V object.

提交回复
热议问题