posted 9 years ago
Well, if I may, the reason the following code doesn't compile has less to do with the comparator (or the lack of comparator in this case) than the type of Map used.
If I replace the previous code with the following, no problem.
But anyway, I agree that the comparator used can help in determining the type and the method reference for grouping.
However, I can't stop thinking this is a little bit weird as the example you gave compiles but the following does not:
And given that I can only assume you tested the examples that are in the book before you inserted them, I would dare to say it is a problem with Java itself.
In the same idea, the code as stated on page 223 (not very different from the one above) doesn't compile either for me (even not with a lambda or an explicit Comparator<String>).