I have read many articles but unable to understand the reason why Concurrent hash map does not allow null key or null values. Some articles gives this explanation:
if (m.containsKey(k)) {
return m.get(k);
} else {
throw new KeyNotPresentException();
}
Since m
is a concurrent map, key k
may be deleted between the containsKey
and get
calls, causing this snippet to return a null that was never in the table, rather than the desired KeyNotPresentException.
But, same would be the case with not-null key. Can anyone please explain the reason for the same.