Community
Participate
Working Groups
Build ID: I20080207-1530 Steps To Reproduce: 1. compile the snippet HashSet<Class<?>> constantClassSet=new HashSet<Class<?>>(); Collections.addAll(constantClassSet, String.class, // utf8 symbols Integer.class, Float.class, Long.class, Double.class // primitive values ); More information: The warning reported by the compiler: Type safety : A generic array of Class<? extends Object> is created for a varargs parameter AnonymousClassLoader.java kijaro-properties/davinci/bootcp/java/dyn line 229 Java Problem13 An array of parameterized type is unsafe because a parameterized type is not a reified type. An array of wildcard type is safe. The compiler infers Class<? extends Object> but doesn't 'see' that Class<? extends Object> is equivalent to Class<?>. Rémi
Argh, the previous test case doesn't exhibit the problem. Should be: HashSet<Class<?>> constantClassSet=new HashSet<Class<?>>(); Collections.addAll(constantClassSet, String.class, Object.class );
This equivalence is not accounted in the spec, hence the compiler diagnosis is accurate I believe. I agree that the underlying bounds are equivalent, but Class<?> is unbound, and benefits from certain privileges wrt to reification where Class<? extends Object>. So unless the spec was to account for it, then we wouldn't be allowed to change this. Note that javac exhibits the same behavior as we do.
Added VarargsTest#test061
Rémi, As you are aware, SE7 adds linguistic support for this via @SafeVarargs annotation. OK to close as is for compliance < 1.7 ?
(In reply to comment #4) > Rémi, As you are aware, SE7 adds linguistic support > for this via @SafeVarargs annotation. OK to close > as is for compliance < 1.7 ? Ok to close. Philippe was right and could have closed that bug. cheers, Rémi
Closing as WONTFIX.
Verified for 3.8M5