For training purposes I am creating Java project that will hold information about animals. There is an abstract class Animals which other will extend.
I would like to create carnivorous interface that in general will take any animal as an argument:
public interface Carnivorous { public void eatAnimal(Animal animal); //alternative way I have tried public <T extends Animal> void eatAnimal2( T animal); } Problem is that in specific implementation I would like to narrow it down to specific classes that extends Animal:
public class Cat extends Animal implements Carnivorous { public Cat(String name, int expierence, String meow) { super(name, expierence); this.meow = meow; } public String getMeow() { return meow; } public void setMeow(String meow) { this.meow = meow; } @Override public String toString() { return "Cat [meow=" + meow + ", name=" + name + ", expierence=" + expierence + "]"; } @Override public void eatAnimal(Animal animal) { // TODO Auto-generated method stub } @Override public <T extends Animal> void eatAnimal2(T animal) { // TODO Auto-generated method stub } In this case I want the cat only to eat a mouse. I don't it to be able to eat let's say a zebra.