我有这个方法():
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
。该列表
界面比较一般,所以作为具体类型声明变量的时候,问问自己,如果这是必要的。看到
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