Converting a list of objects Foo
having an id
, to a Map<Integer,Foo>
with that id
as key, is easy using the stream API:
public class Foo{
private Integer id;
private ....
getters and setters...
}
Map<Integer,Foo> myMap =
fooList.stream().collect(Collectors.toMap(Foo::getId, (foo) -> foo));
Is there any way to substitute the lambda expression: (foo) -> foo
with something using the ::
operator? Something like Foo::this