Java本地嵌套类和访问超级方法

sac*_*ink 7 java nested class super

我有以下类层次结构场景; A类有一个方法,B类扩展了A类,我想从本地嵌套类中调用超类的方法.我希望一个骨架结构更清楚地表明场景Java是否允许这样的调用?

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(){
  }
}
Run Code Online (Sandbox Code Playgroud)

Ern*_*ill 21

你可以使用B.super.getCount()呼叫A.getCount()call().


ada*_*shr 5

你要用 B.super.getCount()