-
Bug
-
Resolution: Not an Issue
-
P2
-
None
-
None
-
None
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.
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.
- duplicates
-
JDK-8027677 microbenchmarks failed with self-reference in initializer
- Closed
- relates to
-
JDK-8024809 javac, some lambda programs are rejected by flow analysis
- Closed
-
JDK-8025762 8.3.3: Clarify that a field cannot be referenced in its own initializer
- Closed
-
JDK-8027677 microbenchmarks failed with self-reference in initializer
- Closed