[UPDATE] The real situation was a bit more complicated than my initial question made it seem. I've changed the code a bit to reflect that.[/UPDATE]
I'm a bit stumped by the following behavior. Given code like:
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 the error:
useT(capture#478 of ?) in Inter<capture#478 of ?> cannot be applied to (java.lang.Object)
Whereas Eclipse gives me:
The method useT(capture#1-of ?) in the type Inter<capture#1-of ?> is not applicable for the arguments (capture#2-of ?)
Obviously, no matter what T
is the result type of makeT()
is the same as the parameter type of useT()
. Why can't I do this? Is there a workaround?