我的代码在Java SE 7中发出警告。如何绕过它没有使用注释来抑制警告;按照预期和 varargs:
import java.util.Iterator;
public class UnionIterator < E > implements Iterator < E > {
public static < E > Iterator < E > newInstance (Iterator < E > ... iterators) {
return new UnionIterator < E >(iterators);
}
private Iterator < E > [] iterators;
private UnionIterator (Iterator < E > ... iterators) {
this.iterators = iterators;
}
@Override
public boolean hasNext() {
// TODO
return false;
}
@Override
public E next() {
// TODO
return null;
}
@Override
public void remove() {
// TODO
}
}
这是警告:
$ javac UnionIterator.java
Note: UnionIterator.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
$ javac -Xlint:unchecked UnionIterator.java
UnionIterator.java:5: warning: [unchecked] Possible heap pollution from parameterized vararg type Iterator<E>
public static < E > Iterator < E > newInstance (Iterator < E > ... iterators) {
^
where E is a type-variable:
E extends Object declared in method <E>newInstance(Iterator<E>...)
UnionIterator.java:11: warning: [unchecked] Possible heap pollution from parameterized vararg type Iterator<E>
private UnionIterator (Iterator < E > ... iterators) {
^
where E is a type-variable:
E extends Object declared in class UnionIterator
2 warnings