List<?> is not equivalent to List<? extends Object>
Alex Buckley
Alex.Buckley at Sun.COM
Mon Apr 21 12:35:46 PDT 2008
Remi,
Please don't bring JLS changes to compiler-dev. OpenJDK is about the
Java platform's implementation, not its spec. As the spec lead for the
Java language and VM, I do not subscribe to compiler-dev and only
occasionally review its archives.
You can file spec defects and RFEs at bugs.sun.com with the Submit A Bug
form:
Product/Category:
Java Platform Standard Edition (JDK/JRE)
Subcategory:
Java Language Spec. and Java Virtual Machine Spec. (specification)
Release:
OpenJDK
Operating System:
// Whatever you like
See also bug 6480391.
Alex
Rémi Forax wrote:
> Hi all,
> the JLS currently considers that List<? extends Object> is not
> equivalent to List<?>.
> List<?> is reified but not List<? extends Object> so they behave
> differently.
>
> It's not a big problem in general, if you want a List<?>, you declare a
> List<?>
> But (there is always a but), when the compiler infers a type argument
> it's more problematic, by example,
>
> HashSet<Class<?>> constantClassSet=new HashSet<Class<?>>();
> Collections.addAll(constantClassSet,
> String.class, Object.class
> );
>
> emits a warning because the second line creates an array of
> Class<? extends Object> which is not safe.
>
> I think it's stupid, i propose to modify section 15.12.2.7 (JLS3) to
> add a line saying that if an inferred type argument is Type<? extends
> Bound>
> with Bound the bound of the type varaible of Type, it is inferred Type<?>.
>
> cheers,
> Rémi
More information about the compiler-dev
mailing list