[UPDATE] The real situation was a little more complicated than my original question. I modified the code a bit to reflect this. [/ UPDATE]
I am a little puzzled by the following behavior. Based on the code:
interface Inter<T> { T makeT(); void useT(T t); } public class Foo { public void bar(Qux q) { Inter<?> x = getInterForQux(q); x.useT(x.makeT()); } Inter<?> getInterForQux(Qux q) { if( someTest(q) ) { return (Inter<Integer>) mkAnInterInt(); } else { return (Inter<Double>) mkAnInterDouble(); } } }
Javac gives me an error:
useT (capture # 478 of?) in Inter <capture # 478 of? > cannot be applied to (java.lang.Object)
While Eclipse gives me:
The useT method (capture # 1-of?) In type Inter <capture # 1-of? > is not applicable for arguments (capture # 2-of?)
Obviously, regardless of the fact that T is the result, the type of the result makeT() same as the type of the parameter useT() . Why can't I do this? Is there a workaround?
source share