Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
See attached test case. import java.util.function.Function; public class LambdaSelfRef { // COMPILATION FAILURE public static Function<Object, Object> op1 = e -> op1.apply(e); // COMPILES OK public static Function<Object, Object> op2 = e -> LambdaSelfRef.op2.apply(e); // COMPILES OK public static Function<Object, Object> op3 = new Function<Object, Object>() { public Object apply(Object o) { return op3.apply(o); } }; // COMPILES OK public static Function<Object, Object> op4 = new Function<Object, Object>() { public Object apply(Object o) { return LambdaSelfRef.op4.apply(o); } }; } The weird thing is that accessing the static field via class works perfectly. Seems to be constrained to lambdas, anonymous classes permit the behavior we are after.
|