Consider this SO answer
I have a few questions:
- How does it work? Does
groupingBy()check if the returned value from theclassifieris aListand compare each and every item? That doesn’t sound like a typical Java function to me - How can
Listcontain different variable types? Does the compiler treat it like aList<Object>? - Is it anti-pattern to use
List?
>Solution :
What is happening here is that the value returned by the classifier is compared using the equals()-method, which in case of a List is specified:
Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.
Actually, the comparing and equals-invoking is done by the underlying Map implementation.