overload resolution with deep nested lambda
anna.kozlova at jetbrains.com
anna.kozlova at jetbrains.com
Wed Sep 10 18:26:08 UTC 2014
Hi,
sorry if the place is inappropriate, hopefully explanation would be
interesting not only for me.
The following sample compiles, though my understanding of the spec says
that it should not:
{code}
class Main {
public static void main(String[] args) {
List<Optional<Function<String, String>>> list =
asList(of((String s) -> identity(s)));
}
static <T> List<T> asList(T a) { return null;}
static <T> List<T> asList(Optional a) { return null;}
static <O> Optional<O> of(O value) { return null;}
public static String identity(final String s) {
return s;
}
}
{code}
Because of((String s) -> identity(s)) is potentially compatible with
both methods (15.12.2.1), method applicability search yields 2 methods
applicable by strict invocation, of which asList(Optional a) is more
specific (according to 18.5.4) but javac obviously chooses asList(T).
Could someone explain what have I missed here please?
Thank you,
Anna
More information about the lambda-dev
mailing list