I'm trying to initialize a ConcurrentHashMap
of ConcurrentHashMap
s with
private final ConcurrentHashMap<
String,
ConcurrentHashMap<String, Double>
> myMulitiConcurrentHashMap = new ConcurrentHashMap<
String,
new ConcurrentHashMap<String, Double>()
>();
but javac
gives
HashMapper.java:132: error: illegal start of type
new ConcurrentHashMap<String, Double>()
^
HashMapper.java:132: error: '(' or '[' expected
new ConcurrentHashMap<String, Double>()
^
HashMapper.java:132: error: ';' expected
new ConcurrentHashMap<String, Double>()
pointing to the second new
.
How can myMulitiConcurrentHashMap
be new
ly initialized properly?
By the way, Java 7 has a more concise syntax now (the "diamond"):
private final
ConcurrentHashMap<String, ConcurrentHashMap<String, Double>>
myMulitiConcurrentHashMap =
new ConcurrentHashMap<>();
You should be able to use interfaces on the left hand side, too:
private final
ConcurrentMap<String, ConcurrentMap<String, Double>>
myMulitiConcurrentHashMap =
new ConcurrentHashMap<>();