initializing a Guava ImmutableMap

后端 未结 3 1906
半阙折子戏
半阙折子戏 2020-12-12 12:47

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 metho

3条回答
  •  我在风中等你
    2020-12-12 13:19

    if the map is short you can do:

    ImmutableMap.of(key, value, key2, value2); // ...up to five k-v pairs
    

    If it is longer then:

    ImmutableMap.builder()
       .put(key, value)
       .put(key2, value2)
       // ...
       .build();
    

提交回复
热议问题