0
请帮我解决了以下内容:覆盖使用不同的返回类型(泛型集合)
- 类
Cat
必须扩展Animal
(保留继承); Animal.getAll()
必须返回所有动物(猫,狗等)和Cat.getAll()
必须只返回猫(不要改变签名)。
我尝试和错误The return type is incompatible with Animal.getAll()
失败的8行
class Animal {
public static List<Animal> getAll() {
return new ArrayList<Animal>();
}
}
class Cat extends Animal {
public static List<Cat> getAll() {
return new ArrayList<Cat>();
}
}
粘贴代码,您是如何调用方法的。 – Kent
你真的打算getAll方法是静态的吗?静态方法不会被继承覆盖。 –
我甚至没有试图唤起他们,因为我得到了写这些行的错误。 – oshilan