Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these correctly declares a map safe for concurrent use?

  • A.Map<String, Integer> m = new HashMap<String, Integer>().concurrent();
  • B.ConcurrentHashMap m = Map.concurrent();
  • C.ConcurrentMap<String, Integer> m = new ConcurrentHashMap<String, Integer>();
  • D.ConcurrentMap<String, Integer> m = new ConcurrentMap<String, Integer>();

Answer: C

ConcurrentMap is the interface and ConcurrentHashMap the implementation, so the interface is used as the variable type and the class is constructed. Neither Map nor HashMap offers a method to convert an existing map in place.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.