I have an interface that looks something like
public interface KeyRetriever {
public Object getKey(Object obj);
}
I want the implementation to be something like
CustomerTypeKeyRetriever (Implementation class)
public String getKey(Customer customer) {
return null;
}
How can I achieve this. Currently it throws a compilation error – “The type CustomerTypeKeyRetriever must implement the inherited abstract method KeyRetriever.getKey(Object)”
Your implementation should have method like
I would also put a @Override annotation to on all my implementaion method so that compiler can catch any method changes/conflicts in future in case API’s change.
In case you want generified interface, below should work (this is what i think you might want)
Here the return type can be any subclass of Object since java supports covariant return types.