我有2个抽象类操作泛型,1个工厂也有泛型。父级独立于行程对象和分解代码。儿子仅以旅行为基础。
//parent
public abstract class AbstractPurchaseExtractor<//
BINDING_CLASS extends ForPnrHandling, //
PURCHASE extends AbstractServicePurchase<?, PRICING, RECEIPT, ITEM, COUPON>, //
PRICING extends PricingDefault, //
RECEIPT extends ReceiptDefault, //
ITEM extends AbstractServiceItem<PURCHASE, COUPON>, //
COUPON extends CouponDefault> //
implements IPurchaseExtractor<BINDING_CLASS, PURCHASE, PRICING, RECEIPT, ITEM, COUPON>
...
//son
public abstract class AbstractTripBasedPurchaseExtractor<//
BINDING_CLASS extends ForPnrHandling, //
TRIP_PURCHASE extends AbstractTripBasedPurchase<?, PRICING, RECEIPT, TRIP_BASED_ITEM, TRIP_BASED_COUPON> , //
PRICING extends PricingDefault, //
RECEIPT extends ReceiptDefault, //
TRIP_BASED_ITEM extends AbstractTripBasedItem<TRIP_PURCHASE, TRIP_BASED_COUPON, ?>, //
TRIP_BASED_COUPON extends TripBasedCouponDefault> //
extends AbstractPurchaseExtractor<BINDING_CLASS, TRIP_PURCHASE, PRICING, RECEIPT, TRIP_BASED_ITEM, TRIP_BASED_COUPON> //
{
@Autowired
private AbstractTripBasedPurchaseFactory<TRIP_PURCHASE, PRICING, RECEIPT, TRIP_BASED_ITEM, TRIP_BASED_COUPON> abstractTripBasedPurchaseFactory;
...
//factory
public abstract class AbstractTripBasedPurchaseFactory<PURCHASE extends AbstractTripBasedPurchase<?, PRICING, RECEIPT, ITEM, COUPON>,
PRICING extends PricingDefault,
RECEIPT extends ReceiptDefault,
ITEM extends AbstractTripBasedItem<? extends AbstractTripBasedPurchase<?, PRICING, RECEIPT, ITEM, COUPON>, COUPON, ?>,
COUPON extends TripBasedCouponDefault>
extends AbstractPurchaseFactory<PURCHASE, PRICING, RECEIPT, ITEM>
{
我在Eclipse上有关于AbstractTripBasedPurchaseExtractor第9行的错误: 绑定不匹配:类型TRIP_PURCHASE不是有界参数的有效替代
<PURCHASE extends AbstractServicePurchase<?,PRICING, RECEIPT, ITEM,COUPON>>
的类型
AbstractPurchaseExtractor<BINDING_CLASS,PURCHASE,PRICING, RECEIPT, ITEM,COUPON>
HERE:extends AbstractPurchaseExtractor'&lt; BINDING_CLASS, TRIP_PURCHASE ...
在子类上使用extends,我需要使用TRIP_PURCHASE来扩展AbstractServicePurchase。实际上AbstractTripBasedPurchase扩展了AbstractServicePurchase。那么为什么会出错?
如果我像Eclipse所期望的那样用AbstractServicePurchase替换AbstractTripBasedPurchase,当然它会编译但是我不能在子类上使用我的旅行工厂。
答案 0 :(得分:0)
最大限度地简化了。
有效。
public interface IGeneric<OBJECT> {
public void test(OBJECT o);
}
public abstract class Parent<OBJECT extends AbstractProduct> implements IGeneric<OBJECT> {
}
public abstract class Son<PRODUCT extends Trip> extends Parent<PRODUCT> {
IService<PRODUCT> service;
}
public abstract class AbstractProduct {
}
public class Trip extends AbstractProduct{
}
public interface IService<TRIP extends Trip> {
}