I have a class Transaction and a Service interface
public class Transaction {}
public interface RequestService {
public String getRequest(Transaction transaction);
}
Now I want to subclass the Transaction class and have a concrete class for the Service Interface
public class ESPTransaction extends Transaction {}
public class ESPRequestService implements RequestService {
@Override
public String getRequest(ESPTransaction espTransaction) {
StringBuffer buff = new StringBuffer(espTransaction.someMethodThatDoesntExistInParentClass());
return buff.toString();
}
}
The IDE complains that, even though ESPTransaction subclasses Transaction, that I am not overriding the supertype method.
How can I implement this?
As the IDE notes,
ESPRequestServiceisn't properly implementingRequestService, since it doesn't have agetRequest(Transaction)method.One neat solution is to make the interface generic, so each
RequestServiceimplementation can specify the type ofTransactionit expects: