Comparator/Comparators API change proposal
forax at univ-mlv.fr
Tue Jun 4 15:32:05 PDT 2013
On 06/04/2013 11:36 PM, John Rose wrote:
> 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?
or because in the inference mechanism, Integer is not recognized as the
boxing of an int,
or if you prefer T -> int is not a specialization of T -> Integer.
> — John
More information about the lambda-dev