Is co-variance safe here?
问题 class Food{} class Meat extends Food{} class Animal{ void feed(Food f){} } class Lion extends Animal{ void feed(Meat m){} } void foo(Animal a){ Food f = new Food(); a.feed(f); } What will happen if we send to foo(new Lion()) ? I know that it will get error but I need the explanation please 回答1: Your Lion can eat Meat , but it can also eat any kind of food (like Spinach). If your Lion could not eat any kind of Food , then it could not be considered an implementation of Animal . This is