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]
# 1
I think Eclipse has it wrong. I'll let them know.
PeterAhea at 2007-7-10 3:37:32 > top of Java-index,Core,Core APIs...
# 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

muleta at 2007-7-10 3:37:32 > top of Java-index,Core,Core APIs...
# 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);

}

}

PeterAhea at 2007-7-10 3:37:32 > top of Java-index,Core,Core APIs...
# 4
Won't compile from JDK. Eclipse says:Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integerat Test.main(Test.java:14)
hwaitea at 2007-7-10 3:37:32 > top of Java-index,Core,Core APIs...
# 5
Thank you, that what was I expected. No warnings, I presume.
PeterAhea at 2007-7-10 3:37:32 > top of Java-index,Core,Core APIs...
# 6
Correct. No warnings.
hwaitea at 2007-7-10 3:37:32 > top of Java-index,Core,Core APIs...