Prateekナレンドラ:
私が持っているMap<String,Object>
Aに変換されますConcurrentMap<String,Object>
Map<String,Object> testMap = new HashMap<String,Object>();
testMap.put("test", null); //This null causing issues in conversion
testMap.put("test2","123");
testMap.put("test3",234);
ConcurrentMap<String,Object> concMap = new ConcurrentHashMap<>(testMap);
私は、ヌルポインタ例外を取得します。私は新しいにコピーする場合HashMap<String,Object>
Map<String,Object> testMap = new HashMap<String,Object>();
testMap.put("test", null);
testMap.put("test2","123");
testMap.put("test3",234);
Map<String,Object> concMap = new HashMap<>(testMap);
私はすべてのエラーを得ることはありません。安全な方法があるMap<String,Object>
のではConcurrentMap<String,Object>
なくてNullPointerException
Skwat:
あなたが表示されますConcurrentHashMapののソースコードに見れば、それはヌルキーまたは値を許可していません -
java.util.concurrent.ConcurrentHashMap#putVal
/** Implementation for put and putIfAbsent */
final V putVal(K key, V value, boolean onlyIfAbsent) {
if (key == null || value == null) throw new NullPointerException();