My question is a follow up of an other guy's question: Unbounded wildcard passed to method
He was interested why the following code compiled:
public class ColTest {
static<T> T wildSub(ArrayList<? extends T> holder, T arg){
T t=holder.get(0);
return t;
}
public static void main(String[] args) {
ArrayList<?> list=new ArrayList<Long>(Arrays.asList(2L,3L,7L));
Long lng=1L;
ColTest.wildSub(list, lng);
}
}
We came to a conclusion that the trick was that compiler inferred the ? as an Object and made the following Long argument pass thanks to the trivial inheritance of Object->Long.
The code does compile using Sun/Oracle javac (I use 1.6.0_26-b03), but does not compile in Eclipse (I use Helios) where it displays the following compilation error:
The method wildSub(ArrayList<? extends T>, T) in the type ColTest is not applicable for the arguments (ArrayList<capture#2-of ?>, Long)
My question is:
Is this a bug in the Java compiler implementation Eclipse uses or some kind of ambiguity in Java 'generics inference algorithm' specification that is valid and just implemented differently by Eclipse?