Java bug using Collectors::toMap() with ArrayList::new

Hi @davehoch,

Thank you for this suggestion. This is indeed a tricky bug.
I expect this problem to be valid every time ArrayList::new, HashMap::new or any other collection constructor is given as a java.util.function.Function argument. It is already rare to set the initial capacity of a collection, it would be even more so to do it via a generic Function.

Thus I would make the rule more generic: “Collections’ constructors should not be used as Functions”.

Of course this rule would raise only when the constructors are given as java.util.function.Function arguments. No issue would be raised when they are provided as java.util.function.Supplier, as it is the case in java.util.stream.Collector.of(...).

Do you see any issue with such a rule?