What is the proper way to call the super method of ParentClass from an anonymous class?
In its current state super is referring to the Runnable.
public class ChildClass extends ParentClass {
@Override
public void myMethod(final double value) {
new Runnable() {
@Override
public void run() {
super.myMethod(value);
}
};
}
}
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);
}
};
}
}
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With