您需要向该类添加类型变量:
public abstract class Animal<F extends AnimalFeed> { public abstract void eat(F somethingToEat);}
然后,您可以将子类声明为需要特定类型的
AnimalFeed:
public class Bird extends Animal<BirdFeed> { public void eat(BirdFeed somethingToEat) {}}public class Fish extends Animal<FishFeed> { public void eat(FishFeed somethingToEat) {}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)