class Main { interface Function { T fun(U t); } interface Sortable { Sortable sort(Comparator c); } static class Inner { String foo() { return ""; } } Comparator comparing(Function mapper) { return null; } void testAssignmentContext(Sortable sortable, boolean cond) { Comparator comparing0 = comparing(Inner::foo); Comparator comparing = comparing((p) -> p.foo()); Sortable p1 = sortable.sort(comparing); Sortable p2 = sortable.sort(comparing(x->x.foo())); Sortable p3 = sortable.sort(cond ? comparing(Inner::foo) : comparing(x -> x.foo())); Sortable p4 = sortable.sort((cond ? comparing(Inner::foo) : comparing(x -> x.foo()))); } void testMethodContext(Sortable 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 { int compare(T o1, T o2); } }