lambda: conditional inference updated

This commit is contained in:
anna
2013-02-25 18:44:13 +01:00
parent 41c7532046
commit b562064e02
5 changed files with 47 additions and 7 deletions
@@ -0,0 +1,36 @@
public class Main {
interface Function<T, U> {
T fun(U t);
}
interface Sortable<X> {
Sortable<X> sort(Comparator<X> c);
}
static class Inner {
String foo() { return ""; }
}
<T2, U2> Comparator<U2> comparing(Function<T2, U2> mapper) { return null; }
void testAssignmentContext(Sortable<Inner> sortable, boolean cond) {
Comparator<Inner> comparing0 = comparing(Inner::foo);
Comparator<Inner> comparing = comparing((p) -> p.foo());
Sortable<Inner> p1 = sortable.sort(comparing);
Sortable<Inner> p2 = sortable.sort(comparing(x->x.foo()));
Sortable<Inner> p3 = sortable.sort(cond ? comparing(Inner::foo) : comparing(x -> x.foo()));
Sortable<Inner> p4 = sortable.sort((cond ? comparing(Inner::foo) : comparing(x -> x.foo())));
}
void testMethodContext(Sortable<Inner> list, boolean cond) {
testMethodContext(list.sort(comparing(Inner::foo)), true);
testMethodContext(list.sort(comparing(x->x.foo())), true);
testMethodContext(list.sort(cond ? comparing(Inner::foo) : comparing(x -> x.foo())), true);
testMethodContext(list.sort((cond ? comparing(Inner::foo) : comparing(x -> x.foo()))), true);
}
interface Comparator<T> {
int compare(T o1, T o2);
}
}