-1

Found this question here at stack overflow: Can you call the parent interface's default method from an interface that subclasses that interface?

new BFunctionalInterface(){
            @Override
            public void doWork() {
            }}.doSomeWork();
            System.out.println("WUK WUK");

I understand its an anonymous class.But what does calling doSomeWork with a "." inside doWork mean?Does it call the implementation of A or B?

Bissi singh
  • 50
  • 1
  • 11

1 Answers1

1

It's calling doSomeWork on the object created via new BFunctionalInterface.

This is clearer if you format it reasonably and remove the extra } from the excerpt (it seems to be the closing } on an enclosing block you haven't shown the start of) which is misleading:

new BFunctionalInterface() {
    @Override
    public void doWork() {
    }
}.doSomeWork();
System.out.println("WUK WUK");

Clearer still if you assign it to a local and then make the call:

BFunctionalInterface instance = new BFunctionalInterface() {
    @Override
    public void doWork() {
    }
};
instance.doSomeWork();
System.out.println("WUK WUK");

Other than the second creating a variable, those do exactly the same thing.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875