I am trying to come up with a more concise expression for the parameter parameter of the "keyMapper" function in the following call to "Collectors.toMap ()":
List<Person> roster = ...; Map<String, Person> map = roster .stream() .collect( Collectors.toMap( new Function<Person, String>() { public String apply(Person p) { return p.getLast(); } }, Function.<Person>identity()));
It seems like I should be able to embed it with a lambda expression, but I can't think of a compilation. (I'm completely new to lambdas, so no wonder.)
Thank.
-> Update:
As noted in the accepted answer
Person::getLast
this is what i was looking for and this is what i tried. However, the BETA_8 nightly build of Eclipse 4.3 was a problem - she noted that it was wrong. When compiling from the command line (which I had to do before publishing) this worked. So, time to download the error from eclipse.org.
Thank.
java collections lambda java-8 java-stream
pfurbacher Oct 08 '13 at 17:57 2013-10-08 17:57
source share