Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define Type of Immutable Map With Builder

I am trying to make a Map<BooleanSupplier, List<String>> as part of my flow I make the suppliers and then try to use an immutable map builder.

Something like:

 //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 the types are not convertible even when I do an explicit cast because the ImmutableMap is of type <Object, Object>. Is there a way to explicitly cast or initialize the immutable map builder to be of type ImmutableMap<BooleanSupplier, List<String>>?

like image 916
ford prefect Avatar asked Jan 29 '16 20:01

ford prefect


1 Answers

Specify the generic type explicitely when calling builder():

Map<BooleanSupplier, List<String>> bsList = 
    ImmutableMap.<BooleanSupplier, List<String>>builder()
        .put(...)
        .build();
like image 191
JB Nizet Avatar answered Oct 28 '22 02:10

JB Nizet