接口和继承:“返回类型 int 不兼容”
2022-09-02 09:06:56
public interface MyInterface{
public int myMethod();
}
public class SuperClass {
public String myMethod(){
return "Super Class";
}
}
public class DerivedClass extends SuperClass implements MyInterface {
public String myMethod() {...} // this line doesn't compile
public int myMethod() {...} // this is also unable to compile
}
当我尝试编译时,它会给我错误DerivedClass
java: myMethod() in interfaceRnD.DerivedClass cannot override myMethod() in interfaceRnD.SuperClass return type int is not compatible with java.lang.String
我应该如何解决这个问题?