3
的Java 7为什么下面的方法不会产生潜在的堆污染?
我写了这个:
public static <E extends Enum<E>> List<SelectItem> getSelectItemList(Enum<E>... es){
List<SelectItem> items = new ArrayList<SelectItem>();
for(Enum<E> e : es){
items.add(new SelectItem(e, e.toString()));
}
return items;
}
而且这种方法没有警告编译。为什么?我预计,这种使用泛型类型的可变参数(这实际上是一个数组)产生
Potential heap pollution via varargs parameter es
你能不能解释一下吗?
它不是'E'数组,而是一个泛型类型为'E'的枚举数组。 – Thomas