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?
implements PetLover<String>? You should clarify what you are trying to achieve hereStringis intended to be the name of a dog. I triedPetlover <String>to no avail (please see Eran's answer below) - the same error is output by the compiler.