lambda binary snapshots

Brian Goetz brian.goetz at oracle.com
Sun Nov 13 07:56:04 PST 2011


Thanks for the bug report (yes, this is the place.)  Obviously the best choice would be for it to select IntMapper<String>.  We'll look into it.  

On Nov 13, 2011, at 4:49 PM, Colin Decker wrote:

> Hmm, neither of them are compiling for me. With both I get:
> 
> error: no suitable method found for comparing(<lambda>)
> method Comparators.<T#1>comparing(DoubleMapper<T#1>) is not applicable
> (cyclic inference - cannot infer target type for given lambda/method reference expression)
> method Comparators.<T#2>comparing(LongMapper<T#2>) is not applicable
> (cyclic inference - cannot infer target type for given lambda/method reference expression)
> method Comparators.<T#3>comparing(IntMapper<T#3>) is not applicable
> (cyclic inference - cannot infer target type for given lambda/method reference expression)
> method Comparators.<T#4,U>comparing(Mapper<T#4,U>) is not applicable
> (cyclic inference - cannot infer target type for given lambda/method reference expression)
> where T#1,T#2,T#3,T#4,U are type-variables:
> T#1 extends Object declared in method <T#1>comparing(DoubleMapper<T#1>)
> T#2 extends Object declared in method <T#2>comparing(LongMapper<T#2>)
> T#3 extends Object declared in method <T#3>comparing(IntMapper<T#3>)
> T#4 extends Object declared in method <T#4,U>comparing(Mapper<T#4,U>)
> U extends Comparable<? super U> declared in method <T#4,U>comparing(Mapper<T#4,U>)
> 
> Changing it to
> 
> Comparator<String> c = Comparators.comparing((String s) -> s.length());
> 
> gets me instead:
> 
> error: reference to comparing is ambiguous, both method <T#1>comparing(LongMapper<T#1>) in Comparators and method <T#2>comparing(DoubleMapper<T#2>) in Comparators match
> where T#1,T#2 are type-variables:
> T#1 extends Object declared in method <T#1>comparing(LongMapper<T#1>)
> T#2 extends Object declared in method <T#2>comparing(DoubleMapper<T#2>)
> 
> which is strange given that length() returns an int.
> 
> The following more explicit variations work:
> 
> Comparator<String> c = Comparators.<String, Integer>comparing(s -> s.length());
> Comparator<String> c = Comparators.comparing((IntMapper<String>) s -> s.length());
> 
> Is this the best place to report this sort of thing?
> 
> -- 
> Colin
> 
> 
> On Sun, Nov 13, 2011 at 10:40 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> They both should compile with the prototype, but note that the prototype compiler still uses the # symbol as the infix operator for method references.
> 
> On Nov 13, 2011, at 4:08 PM, Colin Decker wrote:
> 
> > Is it going to be possible for either of the following statements to compile at some point?
> >
> > Comparator<String> c = Comparators.comparing(s -> s.length());
> > Comparator<String> c = Comparators.comparing(String::length); // String#length now
> >
> > --
> > Colin
> >
> >
> > On Sun, Nov 13, 2011 at 3:33 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> > in general, keep in mind that the library work is all completely speculative and may look nothing like the final product.
> >
> > Composing comparators allows you to impose a dictionary ordering.  So:
> >
> >  Comparator<Person> byLastName = comparing(Person::getLastName);
> >
> >  Comparator<Person> byLastAndFirstName = byLastName.compose(comparing(Person::getFirstName));
> >
> > The second of these will compare by last and first name, that is, when last name is equal, it will resolve ties by comparing first name.
> >
> > Because this is an extension method, the receiver in the invocation becomes the first argument to the default:
> >
> >  foo.compose(bar)
> >
> > becomes
> >
> >  compose(foo, bar)
> >
> > when it is actually executed.
> >
> >
> >
> > On Nov 13, 2011, at 1:52 AM, Arul Dhesiaseelan wrote:
> >
> > > JDK 8 Lambda build is cool. Thanks for making this available!
> > >
> > > I was playing with defender methods, wondering what makes this scenario
> > > work:
> > >
> > > In Comparator, there is a new default method compose() which has single
> > > parameter:
> > >
> > > Comparator<T> compose(Comparator<? super T> other) default
> > > Comparators.compose;
> > >
> > > The default implementation in Comparators has two parameters:
> > >
> > > public static<T> Comparator<T> compose(Comparator<T> first, Comparator<?
> > > super T> second) {}
> > >
> > > For example, the woven class String.CASE_INSENSITIVE_ORDER
> > > (CaseInsensitiveComparator.class) has single parameter. I am not sure I
> > > understand how this works, need help.
> > >
> > > -Arul
> > >
> >
> >
> >
> 
> 



More information about the lambda-dev mailing list