The following are two approaches that create an instance of concurrentHashMap. I understand that approach 2 is thread safe, but not 1. But I'm talking to a colleague and him, since both create an instance of concurrentHashMap shouldn't approach 1 also a thread safe as well?
Approach 1:
private static final Map<key, value> map = new ConcurrentHashMap<key, value>();
Approach 2:
private static final ConcurrentHashMap<key, value> concurrentHashMap = new ConcurrentHashMap<key, value>();
Would thank for any clarification on this.
source
share