2

I have I_class with type parameters I and D:

class I_class<I extends I_class<I,D>, D extends D_class<I,D>>

I also have X_class with the same type parameters:

class X_class<I extends I_class<I,D>, D extends D_class<I,D>>

X_class has the method:

public D produceDeliver(I item) {...}

But when I try to call this method from I_class:

X_class<I, D> x_object = ...    

public D produceDeliver(){ 
         D deliver = x_object.produceDeliver(this);
         ...

I get this error message:

The method produceDeliver(I) in the type X_class< I,D > is not applicable for the arguments (I_class< I,D >)

I don't understand the non-equivalence between I and I_class< I,D >, since I extends I_class< I,D >

ftkg
  • 1,652
  • 4
  • 21
  • 33

1 Answers1

2

An example with more concrete names might be helpful:

class Building<B extends Building<B, X>, X extends Thing<B, X>> {
  Shop<B,X> s = new Shop<>();
  X makesError = s.getLocation(this);
}
class Shop<S extends Building<S, X>, X extends Thing<S, X>> {
   public X get_location(S shop) {...}
}

The problem is that when you are invoking getLocation, you are passing an argument of type Building. Not every instance of type Building is of type Shop.

Chris Owens
  • 1,107
  • 1
  • 10
  • 15