capture confusion
I got the following to compile in Eclipse but javac doesn't seem to like it. Who's Better, Who's Best?
import java.util.List;
class Test{
Test(){
Class<?extends List<?>> cls =null;
foo(cls);
}
<I,Textends List><I>> T foo(Class<T> pClass){returnnull;}
}
[740 byte] By [
hwaitea] at [2007-11-26 21:47:18]

# 2
Thanks for the notification. I think I meant to improve inference for <I> to use hints from the bounds of already inferred type variables.
JLS15.12.2.8 doesn't require this though. However, it feels a small addition with nice end results.
In first pass (with arguments), <T> is inferred to be: <capture#1-of ? extends List><?>>
If this information is injected amongst the hints for inferring <I> in second pass (15.12.2.8), then <I> is inferred to be <?>, rather than <java.lang.Object>.
I think this behavior is a nice enhancement, but this should be blessed in the spec.
Entered: https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715
# 3
What happens when you run this program?
import java.util.*;
class Test {
public static void main(String... args) {
List<List><?>> lists = new ArrayList<List><?>>();
List<? extends List<?>> xyz = lists;
List<String> strings = new ArrayList<String>();
strings.add("a string");
List<Integer> integers = new ArrayList<Integer>();
lists.add(strings);
lists.add(integers);
foo(xyz);
System.out.println(integers.get(0).intValue());
}
static <I,T extends List><I>> void foo(List<T> arg) {
I i = arg.get(0).get(0);
arg.get(1).add(i);
}
}