ArrayList的是一种原始类型。引用泛型类型的ArrayList&LT; E&GT;应该是参数化 [英] ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
问题描述
我有这个方法():
private List<? extends Map<String, String>> creaListaDeGrupos() {
ArrayList resultado_padre = new ArrayList();
for (int i = 0; i < listadoPartidas.getPartidas().size(); i++) {
HashMap<String, String> padre = new HashMap<String, String>();
padre.put("posicionLista", posicionlista.get(i));
padre.put("codigo", codigoBaremo.get(i));
padre.put("descripcionBaremo", descripcionBaremoPadre.get(i));
padre.put("cantidad", cantidad.get(i));
padre.put("importe", importe.get(i));
padre.put("estado", estado.get(i));
padre.put("observaciones", observaciones.get(i));
resultado_padre.add(padre);
}
return resultado_padre
}
和皮棉返回我的错误:
ArrayList的是原始类型。引用泛型类型的ArrayList应当参数化
ArrayList is a raw type. References to generic type ArrayList should be parameterized
但我不能做
ArrayList<String> resultado_padre = new ArrayList();
由于这个心不是一个ArrayList的字符串,什么类型的胸围会是什么?
Because this isnt a arraylist of strings, what type bust will be?
推荐答案
您可以尝试创建同一类型,你正在返回:
You could try creating the same type you are returning:
List<HashMap<String, String>> = new ArrayList<HashMap<String, String>>();
有没有必要宣布实现类型,即的ArrayList
。该列表
界面比较一般,所以作为具体类型声明变量的时候,问问自己,如果这是必要的。看到
<一href="http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface">Programming对接口
There is no need to declare the implementation type, i.e. ArrayList
. The List
interface is more general, so when declaring variables as a concrete type, ask yourself if this is necessary. See
Programming against interface
这篇关于ArrayList的是一种原始类型。引用泛型类型的ArrayList&LT; E&GT;应该是参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!