Created
January 28, 2016 10:14
-
-
Save techtangents/66f5d4578d9b9e3a0475 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Function; | |
public class Blah { | |
private Blah() { | |
} | |
static class A { | |
} | |
static class B extends A { | |
String foo(final String x) { | |
return x + "!"; | |
} | |
} | |
static void f1(final Function<A, Void> k) { | |
k.apply(new A()); | |
} | |
static void f2(final Function<B, Void> k) { | |
f1(k); // compile error - quite rightly: "b => Void" is not an "a => Void" | |
} | |
static { | |
f2(x -> { | |
System.out.println(x.foo("ABC")); | |
return null; | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment