Consider the following generic interface:
interface Petlover<T>{
void train(T somePet);
}
I understand that it's possible to provide generic implementations to generic interfaces (e.g., class MalePetLover<T> implements Petlover<T>). But I am having trouble implementing the interface for a specific type only:
class Dogperson implements Petlover<T> {
int age;
void train(String someDog){...};
}
The compilation error is train(String) in Dogperson cannot implement train(T) in Petlover. What would be a right way to handle this?
Since you expect train to accept a String, your class should implement Petlover<String>:
class Dogperson implements Petlover<String> {
int age;
public void train(String someDog) {...};
}
or perhaps the train() method of Dogperson should accept a Dog argument, and then the class would implement Petlover<Dog>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With