According to JLS:
15.9.5 Anonymous class declarations An anonymous class declaration is automatically inferred from the class instance creation expression using the compiler.
An anonymous class is not abstract (ยง8.1.1.1). An anonymous class is always an inner class (ยง8.1.3); it is never static (ยง8.1.1, ยง8.5.2). An anonymous class is always implicitly final (ยง8.1.1.2) .
It seems that this was a specific design decision, so it is likely that he has some history.
If I choose a class like this:
SomeType foo = new SomeType() { @Override void foo() { super.foo(); System.out.println("Hello, world!"); } };
Why am I not allowed to subclass it again if I choose this?
SomeType foo = new SomeType() { @Override void foo() { super.foo(); System.out.println("Hello, world!"); } } { @Override void foo() { System.out.println("Hahaha, no super foo for you!"); } };
I'm not saying that I definitely want, or I can even think about the reason why I would do it. But I'm curious why that is.
source share