Comparator/Comparators API change proposal
john.r.rose at oracle.com
Tue Jun 4 14:36:32 PDT 2013
On Jun 3, 2013, at 2:33 PM, Henry Jen <henry.jen at oracle.com> wrote:
> 2. Rename various comparing methods to comparing, comparingInt,
> comparingLong and comparingDouble accordingly.
This seems like a code smell. Let me see if I understand the issue:
When users sort with primitive-valued key extractors, they will have to add noise words "Int", etc., to their code to get the compiler to accept the code.
These noise words exist only to get past a technical overloading difficulty, and do not capture logical details of interest to the user.
Moreover, if users leave out the noise words, the code will still compile and work almost* the same (due to autoboxing).
(*Because java.lang.Double comparison is a little different from double comparison.)
E.g., comparing(String::length) == comparing( (Function<String,Integer>) String::length ) == comparing( (String s)->s.length() ).
This extra help to the compiler is needed because it doesn't know IntFunction<T> is preferable to Function<T,Integer>, when resolving overloadings.
That is because IntFunction<T> does not extend Function<T,Integer>.
Is that right?
More information about the lambda-libs-spec-observers