泛型对象的应用:常规业务逻辑模板化,使用通用的父类来定义字段,具体字段由实现类来赋予数据
泛型对象的应用:常规业务逻辑模板化,使用通用的父类来定义字段,具体字段由实现类来赋予数据
//DEMO-1 public interface CommonTemplateService<T,F> { public T buildCallbackParam(String orderNo); public F doCallback(String callbackUrl, String requestBody); } //实现类继承 public class UserService extends AbstractCommonService implements CommonTemplateService<PartnerBaseRequest, PartnerBaseResponse> { //DEMO-2 public interface CommonTemplateService { public PartnerBaseRequest buildCallbackParam(String orderNo); public PartnerBaseResponse doCallback(String callbackUrl, String requestBody); } //实现类继承 public class UserService extends AbstractCommonService implements CommonTemplateService { //支付宝源码代码参考: public interface AlipayRequest<T extends AlipayResponse>{ public abstract class AlipayResponse implements Serializable { public <T extends AlipayResponse> T execute(AlipayRequest<T> request) throws Exception { } //实现类 public class AlipayAcquirePayRequest extends BaseVo implements AlipayRequest<AlipayAcquirePayResponse>{