Code like:
protected Interface1 varClass1 = new Interface1() {
But I would also like that this anonymous nested class also extends the class Base
, something like:
protected Interface1 varClass1 = new Interface1() extends Base {
....
Is this possible in Java?
An anonymous class can either implement exactly one interface or extend one class.
One workaround is to create a named class that extends Base
and implements Interface1
, and then use that as the base class for the anonymous class:
public abstract class Base1 extends Base implements Interface1 {}
...
protected Interface1 varClass1 = new Base1() {
...