Define immutable map type using Builder

I am trying to make Map<BooleanSupplier, List<String>> part of my stream. I make providers and then try to use an immutable map builder.

Sort of:

  //Build up BooleanSuppliers Map<BooleanSupplier, List<String>> bsList = ImmutableMap.builder() .put(bs1, Collections.singletonList("bs1string")) .put(bs2, Arrays.asList("bs4","bs6")) .... .build(); 

The problem is that intellij says that types are not converted, even if I do an explicit cast, because ImmutableMap is of type <Object, Object> . Is there a way to explicitly specify or initialize an immutable map ImmutableMap<BooleanSupplier, List<String>> like ImmutableMap<BooleanSupplier, List<String>> ?

+5
source share
1 answer

Specify the generic type explicitly when calling builder() :

 Map<BooleanSupplier, List<String>> bsList = ImmutableMap.<BooleanSupplier, List<String>>builder() .put(...) .build(); 
+8
source

Source: https://habr.com/ru/post/1241850/


All Articles