Let's say I have the following two class/interface definitions:
public abstract class FooClass {
public abstract void doFoo();
}
and
public interface BarInterface {
public void doBar();
}
If I want to make an anonymous inner class that extends/implements both, do I need to do this:
public abstract class BothClass extends FooClass implements BarInterface {}
...
new BothClass() {
public void doFoo() {
System.out.println("Fooooooooo!!!!");
}
public void doBar() {
System.out.println("Baaaaaaaar!!!!");
}
}.doBar();
Or is there a short-cut that allows me to not define BothClass
? Something like this, maybe:
new (FooClass implements BarInterface)() {
public void doFoo() {
System.out.println("Fooooooooo!!!!");
}
public void doBar() {
System.out.println("Baaaaaaaar!!!!");
}
}.doBar();
(This idea gives me several errors, none of which are helpful here)