Reputation: 395
I have following class hierarchy scenario; Class A has a method and Class B extends Class A, where I want to call a method from super class from a locally nested class. I hope a skeletal structure picture the scenario more clearly Does Java permit such calls?
class A{
public Integer getCount(){...}
public Integer otherMethod(){....}
}
class B extends A{
public Integer getCount(){
Callable<Integer> call = new Callable<Integer>(){
@Override
public Integer call() throws Exception {
//Can I call the A.getCount() from here??
// I can access B.this.otherMethod() or B.this.getCount()
// but how do I call A.this.super.getCount()??
return ??;
}
}
.....
}
public void otherMethod(){
}
}
Upvotes: 7
Views: 3726
Reputation: 26139
Something along the lines of
package com.mycompany.abc.def;
import java.util.concurrent.Callable;
class A{
public Integer getCount() throws Exception { return 4; }
public Integer otherMethod() { return 3; }
}
class B extends A{
public Integer getCount() throws Exception {
Callable<Integer> call = new Callable<Integer>(){
@Override
public Integer call() throws Exception {
//Can I call the A.getCount() from here??
// I can access B.this.otherMethod() or B.this.getCount()
// but how do I call A.this.super.getCount()??
return B.super.getCount();
}
};
return call.call();
}
public Integer otherMethod() {
return 4;
}
}
perhaps?
Upvotes: 4
Reputation: 81684
You can just use B.super.getCount()
to call A.getCount()
in call()
.
Upvotes: 21