Type variable as wildcard bound

Zhong Yu zhong.j.yu at gmail.com
Tue Nov 15 14:23:06 PST 2011


Hi team, I don't understand the behavior of javac7 u2 b11 on the following code:

   class G<N extends Number> {}

   <T> void f1(G<? extends T> k){} //error. why?

   <T> void f2(G<? super   T> k){} //ok. why?

With capture conversion applied, in f1, we have upper bound T&Number,
lower bound null. I don't see any problem here, even if for some T,
T&Number=null. Is the combination of T&Number illegal?

In f2, we have upper bound Number, lower bound T. Since it's not true
that T<:Number, I don't see why this should compile.

Both f1() and f2() compiles under javac 6.

cheers,
Zhong Yu



More information about the compiler-dev mailing list