2
votes

i have 2 abstract classes manipulating generics and 1 factory with generics too. The parent is independent of trips objects and factorize code. The son is based on trips only.

//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>
{

i have the error on Eclipse for AbstractTripBasedPurchaseExtractor line 9 : Bound mismatch: The type TRIP_PURCHASE is not a valid substitute for the bounded parameter

<PURCHASE extends AbstractServicePurchase<?,PRICING, RECEIPT, ITEM,COUPON>> 

of the type

AbstractPurchaseExtractor<BINDING_CLASS,PURCHASE,PRICING, RECEIPT, ITEM,COUPON>

HERE: extends AbstractPurchaseExtractor '< BINDING_CLASS, TRIP_PURCHASE ...

using extends on the son class, i need to use for TRIP_PURCHASE something that extends AbstractServicePurchase. Actually AbstractTripBasedPurchase extends AbstractServicePurchase. So why the error ?

if i replace AbstractTripBasedPurchase by AbstractServicePurchase as Eclipse is expecting, of course it compiles but i cannot use my trip factory on the son class.

1
That's too many generic types for me to grok right now, but at first glance, having a wildcard (?) in there is maybe not so great. Does it help if you replace with it with a type placeholder?Thilo
no, i don't need to replace the wildcard here (?) There is no problem with that. The thing is the extends is expecting me to declare a AbstractServicePurchase class but i pass a son of this class named AbstractTripBasedPurchase. Is weird that is no accepting it, like inheritance is not workingBenjamin Fuentes
can you reduce this to a minimal example that still exhibits the problem?Thilo
It sounds weird because it compiles with Maven but my java file is red of errors on Eclipse Kepler ... Eclipse bug ???Benjamin Fuentes
Holy mother of cows!Ionuț G. Stan

1 Answers

0
votes

The same simplified at maximum.

It works.

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> { 
}