我终于开始尝试摆脱 Java 7 友好生成的所有那些新的编译器警告。我这两个离开了我无法理解的。有什么方法可以在不压制它们的情况下摆脱它们?
构造一个泛型对象数组(我可以在哪里放置一个数组创建?):
static final int N = 10;
//warning: [unchecked] unchecked conversion
static final Set<Widget>[] queued = new ConcurrentSkipListSet[N];
//required: Set<Widget>[]
//found: ConcurrentSkipListSet[]
通用可变参数(似乎几乎在我接受通用类型可变参数的所有地方都会发生):
class Foo<T> {
//warning: [unchecked] Possible heap pollution from parameterized vararg type T
public void add(T... entries) {
//where T is a type-variable:
//T extends Object declared in class Foo
顺便说一句:我已经有:
// Add many entries to the list.
public void add(List<T> entries) {
// ...
}
// Add a number of entries.
public void add(T... entries) {
// Make a list of them.
add(Arrays.<T>asList(entries));
}