Collectors.toMap() keyMapper function question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Collectors.toMap() keyMapper function question

pfurbacher
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Collectors.toMap() keyMapper function question

Michael Nascimento
Person::getLast()

Regards,
Michael

On Tue, Oct 8, 2013 at 2:01 PM, pfurbacher <[hidden email]> wrote:

> I'm wondering how to more succinctly express the "keyMapper" function which
> is highlighted in the following:
>
>        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()));
>
> Thanks.
>
>
>
>
>
> --
> View this message in context: http://openjdk.5641.n7.nabble.com/Collectors-toMap-keyMapper-function-question-tp159371.html
> Sent from the OpenJDK General discussion mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Collectors.toMap() keyMapper function question

pfurbacher
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Collectors.toMap() keyMapper function question

Michael Nascimento
Sorry, it should be Person::getLast. It should work, afaik.

Regards,
Michael

On Tue, Oct 8, 2013 at 3:05 PM, pfurbacher <[hidden email]> wrote:

> Michael Nascimento wrote
>> Person::getLast()
>
> Thanks, but ...
>
> Are you sure? I'm using a very recent nightly build of Eclipse BETA_8, and
> that is flagged as
>
>>    The method getLast() is undefined for the type Sources
>
> I though method references didn't have parens at the end, so I tried
>
> Person::getLast
>
> and that produces
>
>> Type mismatch: cannot convert from Map
>> &lt;
>> Object,Person
>> &gt;
>>  to Map
>> &lt;
>> String,Person
>> &gt;
>
> Perhaps I need to file a bug with Eclipse?
>
> Thanks.
>
>
>
>
> --
> View this message in context: http://openjdk.5641.n7.nabble.com/Collectors-toMap-keyMapper-function-question-tp159371p159384.html
> Sent from the OpenJDK General discussion mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Collectors.toMap() keyMapper function question

pfurbacher
CONTENTS DELETED
The author has deleted this message.