Collections.enumeration() WAS Warning Cleanup Day
Rémi Forax
forax at univ-mlv.fr
Sat Dec 3 04:37:17 PST 2011
I've started to remove warnings from java.util
and I'm not able to cleanly retrofit java.util.PropertyPermission
because java.util.Collections.enumeration is wrongly typed.
PropertyPermission contains a member class that define
a PermissionCollection that store/load only PropertyPermissions.
One method of PermissionCollection returns an Enumeration
of Permission by calling Collections.enumeration.
But Collections.enumeration doesn't use a wildcard.
This is the actual code of Collections.enumeration is
public static <T> Enumeration<T> enumeration(final Collection<T> c) {
return new Enumeration<T>() {
private final Iterator<T> i = c.iterator();
public boolean hasMoreElements() {
return i.hasNext();
}
public T nextElement() {
return i.next();
}
};
}
and should be:
public static <T> Enumeration<T> enumeration(final Collection<? extends
T> c) {
final Iterator<? extends T> i = c.iterator();
return new Enumeration<T>() {
public boolean hasMoreElements() {
return i.hasNext();
}
public T nextElement() {
return i.next();
}
};
}
I believe this change is source and binary compatible because the method
is static and a Collection<? extends T> is a super type of Collection<T>.
Rémi
More information about the jdk8-dev
mailing list