Javac incorrectly claims that class is abstract

Michael Strauß michaelstrau2 at gmail.com
Sat Jun 28 15:50:16 UTC 2025


The following program produces a compiler error on 24.0.1:

abstract class Base<T> {}
abstract class Derived1<T> extends Base<T> {}
abstract class Derived2<T> extends Base<T> {
    Derived2(Derived1<T> obj) {}
}

Base<String> obj = new Derived2<>(
    new Derived1<>() {
        // not abstract
    }) {
        // not abstract
    };

--> error: Derived1 is abstract; cannot be instantiated


However, when I explicitly specify the inferred type argument in
either Derived1<String> or Derived2<String>, the program compiles:

Base<String> obj = new Derived2<String>(
    new Derived1<>() {
        // not abstract
    }) {
        // not abstract
    };

--> OK


More information about the compiler-dev mailing list