javac is failing to compile this code:
abstract class Base<T> {}
abstract class Derived1<T> extends Base<T> {}
abstract class Derived2<T> extends Base<T> {
Derived2(Derived1<T> obj) {}
}
class Test {
Base<String> obj = new Derived2<>(new Derived1<>() { /* not abstract */ }) { /* not abstract */ };
}
issuing error message:
Test.java:8: error: Derived1 is abstract; cannot be instantiated
Base<String> obj = new Derived2<>(new Derived1<>() { /* not abstract */ }) { /* not abstract */ };
basically during speculative attribution the class body of the anonymous classes above is removed to avoid side-effects during the process. It seems like we are checking this condition on a speculative version of the anonymous class
reported in compiler-dev: https://mail.openjdk.org/pipermail/compiler-dev/2025-June/030916.html
abstract class Base<T> {}
abstract class Derived1<T> extends Base<T> {}
abstract class Derived2<T> extends Base<T> {
Derived2(Derived1<T> obj) {}
}
class Test {
Base<String> obj = new Derived2<>(new Derived1<>() { /* not abstract */ }) { /* not abstract */ };
}
issuing error message:
Test.java:8: error: Derived1 is abstract; cannot be instantiated
Base<String> obj = new Derived2<>(new Derived1<>() { /* not abstract */ }) { /* not abstract */ };
basically during speculative attribution the class body of the anonymous classes above is removed to avoid side-effects during the process. It seems like we are checking this condition on a speculative version of the anonymous class
reported in compiler-dev: https://mail.openjdk.org/pipermail/compiler-dev/2025-June/030916.html