2014-06-19 88 views
0

请帮我解决了以下内容:覆盖使用不同的返回类型(泛型集合)

  1. Cat必须扩展Animal(保留继承);
  2. 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>(); 
    } 
} 
+0

粘贴代码,您是如何调用方法的。 – Kent

+0

你真的打算getAll方法是静态的吗?静态方法不会被继承覆盖。 –

+0

我甚至没有试图唤起他们,因为我得到了写这些行的错误。 – oshilan

回答