我有以下類層次結構方案;類A有一個方法,而類B擴展了類A,我想從本地嵌套類的超類中調用一個方法。 我希望骨架結構更清晰地描述場景 Java是否允許這樣的調用?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(){
}
}
您真的確定要調用內部類的外部類的重寫方法實現嗎?看起來像一個正確的混亂給我。 – 2012-01-13 17:02:56
@湯姆霍金 - 我認爲這是一個「本地匿名」類而不是「內部」類 - 這使得它更加混亂。 – emory 2012-01-13 17:34:28
@emory從技術上講,匿名內部類是本地類是內部類。 – 2012-01-13 17:38:23