我读了这个问题并认为如果有人可以写的话很容易解决(不是没有它可以解决):
@Override
public String toString() {
return super.super.toString();
}
Run Code Online (Sandbox Code Playgroud)
我不确定它在许多情况下是否有用,但我想知道为什么它不是,如果这样的东西存在于其他语言中.
你们有什么感想?
编辑: 澄清:是的,我知道,这在Java中是不可能的,我不会真的错过它.这不是我期望的工作,并且惊讶于编译错误.我刚才有了这个想法并想讨论它.
我有3个类,他们互相继承如下:
A
?
B
?
C
Run Code Online (Sandbox Code Playgroud)
在每个类中,我有以下方法:
protected void foo() {
...
}
Run Code Online (Sandbox Code Playgroud)
课内C我想打电话foo从类A没有调用foo在B:
protected void foo() {
// This doesn't work, I get the following compile time error:
// Constructor call must be the first statement in a constructor
super().super().foo();
}
Run Code Online (Sandbox Code Playgroud)
编辑
一些上下文信息:
B类是我们使用的实际类.C类是一个单元测试类,它有一些修改.foo里面的方法B做了一些我们不想要的东西,所以我们在里面覆盖它C.但是foo在课堂A上很有用,需要调用.