I think this might be related to Why does a generic cast of a List extends Set..> to List
Strictly according to the spec, T
cannot be inferred (per 15.12.2.7), so it should be taken as Object
.
This can be viewed as a failure of the spec. This is how spec infers R
: first there is constraint R :> BigDecimal
, where :>
means is a supertype of. The inference rules then choose R=BigDecimal
since it's the most specific type satisfying the constraint.
Now, since T:>R
, T:>BigDecimal
, one would think this should yield T=BigDecimal
too.
Unfortunately the inference rules do not take T:>R
into account. There is no contraint on T
. T
is not inferred through the same principle.
While it sucks, spec is spec. Your code should not compile. Javac6 is wrong there.
In Java 8 there's an great improvement on inference rules to make lambda expression easier to use. Hopefully your code should compile in Java 8.