我有一个看起来像这样的 ConcurrentHashMap:private Map<String,Map<String,Set<PublicKey>>> instancePairs = new ConcurrentHashMap<>();以及一个应该填充此哈希图的方法。但我无法弄清楚如何将值放入地图中目前我有:instancePairs.putIfAbsent(inMemoryInstance.getUsername(), inMemoryInstance.getId() , publicKeySet);Intellij Idea 给我这个错误:
1 回答

凤凰求蛊
TA贡献1825条经验 获得超4个赞
正如“DDovzhenko”所提到的,你需要按照以下几行做一些事情。
//Get the map containing the ID as keys, if it doesn't exist, then create one.
Map mapValuesForName = instancePairs.getOrDefault(inMemoryInstance.getUsername(), new ConcurrentHashMap<String,Set<PublicKey>>());
//Put the publicKeySet based on the Id.
mapValuesForName.putIfAbsent(inMemoryInstance.getId(), publicKeySet);
//Store the potentially changed/new value back in original map.
instancePairs.put(mapValuesForName);
添加回答
举报
0/150
提交
取消