There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Mike,
for the toMap you need two mappers, one that maps the element to a key, and one that maps the element to a value (and if there is a possibility of having non unique keys, a BiFunction that tells what to do with the values in that case). You already have the key mapper, you need a value mapper. So the second argument would be: word -> word, or somewhat more stylish: Function.identity().
In that last case: why does the method reference: Function::identity not work?
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Given that you must deal with synonyms, a Map<String, List<Word>> seems more reasonable.
With the toMap, it means that when we have two equal Strings, we need to put the two associated Words into a List. Now, that is not so easy to accomplish with the toMap method, but the alternative mappng method is in this case very much easier. I'm talking about the Collectors.groupingBy method. See the API of the Collectors class; we can use the simplest version, only specifying the key. So we get:
Piet Souris wrote:In that last case: why does the method reference: Function::identity not work?
There are three kinds of actuaries: those who can count, and those who can't.
Stephan van Hulst wrote:Function.identity() takes no arguments and returns a Function<T,T>, so Function::identity is a Supplier<Function<T,T>>, not a Function<T,T>.
In other words, Function.identity() supplies the identity function, it's not the identity function itself.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:why do you use a Word factory 'valueOf', instead of a good old fashioned constructor? Is that the current trend perhaps?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
There are three kinds of actuaries: those who can count, and those who can't.