I have a reference:
public final static LinkedHashMap<String, Function<OrderBean, String>> DELEGATES;
Which I initialize like:
static {
LinkedHashMap<String, Function<OrderBean, String>> tmp = new LinkedHashMap<>();
tmp.put(OrderCols.FIELD1, OrderBean::getFIELD1);
tmp.put(OrderCols.FIELD2, OrderBean::getFIELD2);
...
DELEGATES = Collections.unmodifiableMap(tmp);
}
On the last line of the static block (the assignment to DELEGATES), I get this compiler error:
Error:(64, 48) java: incompatible types: no instance(s) of type variable(s) K,V exist so that java.util.Map conforms to java.util.LinkedHashMap>
Am I messing something up? Or do unmodifiable views don't like Function types?
No, your issue is that instead of
you should have
...because
unmodifiableMap
returns a bareMap
implementation. (The backing data structure will still be aLinkedHashMap
, though.)