Calling a super method in an anonymous class

What is the correct way to call the super ParentClass method from an anonymous class?

In the current state, super refers to Runnable.

public class ChildClass extends ParentClass {

    @Override
    public void myMethod(final double value) {

        new Runnable() {
            @Override
            public void run() {
                super.myMethod(value);
            }
        };
    }
}
+4
source share
2 answers

You can use the following code:

public class ChildClass extends ParentClass {
    @Override
    public void myMethod(final double value) {
        new Runnable() {
            @Override
            public void run() {
                ChildClass.super.myMethod(value);
            }
        };
    }
}
+13
source

call ChildClass.super.myMethod(value);

Note . You can also use ChildClass.this.myAttribute/ ChildClass.this.myMethod()if you want to access instance attributes / methods from ChildClass.

+4
source

All Articles