mergeWith(X) in ... cannot be applied to X

H

HK

Well, in fact the message reads:

Machine.java:19: mergeWith(Action<capture of ? super CDTA>) in
Action<capture of ? super CDTA> cannot be applied to (Action<capture of
? super CDTA>)
a1.mergeWith(a2);

So this is seriously strange, isn't it. I guess two
`capture of's are generally not compatible, but why?

Harald.
 
E

E.Otter

Looking at the Java lang spec v3 (free download from sun and covers v5) and
trying to translate its super-techno-babble on pgs 89-91 on Capture
Conversions into something understandable, I would say basically the
compiler must gaurantee that the parameter types of one thing be safely
assignable to the other thing without a cast in all situations. In the case
of two <? super CDTA> that can't be gauranteed. I think the logic goes like
this, if CDTA extends ClassB and ClassB extends ClassA, then ClassB could
used with one Action and ClassA with the other, but a ClassA object can't be
assigned to a ClassB reference.

You might be able to redo the class with one ? super CDTA and the other ?
extends CDTA or do something like this:
public class Action<T super CDTA>> {

public void mergeWith(Action<T>) { }

}

Ouch my head hurts, it really hurts...
E.Otter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top