Guava offers a nice shortcut for initializing a map. However I get the following compiler error (Eclipse Indigo) when my map initializes to nine entries.
The method of(K, V, K, V, K, V, K, V, K, V) in the type ImmutableMap is not applicable for the arguments
(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)
ImmutableMap<String,String> myMap = ImmutableMap.of(
"key1", "value1",
"key2", "value2",
"key3", "value3",
"key4", "value4",
"key5", "value5",
"key6", "value6",
"key7", "value7",
"key8", "value8",
"key9", "value9"
);
The message appears to say that
An ImmutableMap has a maximum size of four pairs of key,value.
Obviously, this cannot be the case but I can’t figure out what to do to increase the size of my initializer.
Can someone tell me what is missing?
Notice that your error message only contains five
K, Vpairs, 10 arguments total. This is by design; the ImmutableMap class provides six differentof()methods, accepting between zero and five key-value pairings. There is not anof(...)overload accepting a varags parameter becauseKandVcan be different types.You want an
ImmutableMap.Builder: