I have a collection of Long, and for a reason I need to create a map from this collection, which has the elements of the collection as keys, and 1 predefined Enum as value (all keys have the same value).
I am trying to achieve this with Streams, like below:
private Map<Long, Marker> mapMarker(Collection<Long> ids, Marker marker) {
return ids.stream().collect(Collectors.toMap(Function.identity(), marker));
}
Compiler failed with this error:
no instance(s) of type variable(s) T, U exist so that Marker conforms to Function<? super T, ? extends U>
Could someone please explain to me why would it fails? Is there anyway to get the expected result with Streams?