0

Why a null key is not allowed in ConcurrentHashMap?

In HashMap, it is allowed and in HashTable it is not allowed.

Already visited the link :Why does ConcurrentHashMap prevent null keys and values?

But I need the actual reason not the guesses.

  • maybe this brings a light to your question : https://stackoverflow.com/questions/25932730/hashmap-with-null-key-and-null-value – nafas Feb 21 '18 at 11:42
  • The link is related to HashMap and I want to know why null is not allowed in ConcurrentHashMap. – Prashant Agarwal Feb 21 '18 at 11:44
  • @nafas, I have already visited the same link and I am not getting the proper explanation. That post mainly contains different guesses of different people.I want to know the exact reason behind that. – Prashant Agarwal Feb 21 '18 at 11:46
  • the provided dup link by Jon Skeet is spot on answer. – nafas Feb 21 '18 at 11:48
  • Is there a good reason why you should allow that? Imo they could have banned `null` from the maps completely. If it's not written in the documentation and you don't ask the author, a user guess is as close as you can get. Also, note that it could be a pure design choice, without any particular good reason. Maybe it has to do with the internal implementation of the map, maybe it is hard to manage a `null` as key. Maybe it is hard to manage it for possible future updates to the implementation. – Zabuzard Feb 21 '18 at 12:03
  • @Zabuza You want to say that no one knows the exact reason and we can only guess that. – Prashant Agarwal Feb 22 '18 at 09:18

0 Answers0