Is this possible in Java: Map<SomeObject, Map<SomeOtherObj开发者_JAVA百科ect>>
? I'm trying Map<Integer, Map<String>>
am getting an
"Incorrect number of arguments for type Map; it cannot be parameterized with arguments "
error.
Every Map
needs to be parametrized on two types; your second (nested) Map has only one.
A Map
maps keys to values, so Map<String>
is incorrect. So you'd need something like Map<String, Object>
.
You need a second argument on your second Map<>
. Perhaps you mean Map<Integer, Map<String, String>>
?
No, not really like that. You need to give a type for both Key
and Value
for the second "inner" Map
, this is ok:
Map<SomeObject, Map<SomeOtherObject, Object>>
Just like with the outer Map
, where the Key
is SomeObject
, and Value
is the inner Map
. So, if you add a value specification for the inner Map
is, that would be ok.
精彩评论