ArrayList 是原始类型.对泛型类型 ArrayList<E> 的引用应该参数化 [英] ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
本文介绍了ArrayList 是原始类型.对泛型类型 ArrayList<E> 的引用应该参数化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个方法():
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
}
Lint 返回错误信息:
And Lint return me the error:
ArrayList 是原始类型.对泛型类型 ArrayList 的引用应该被参数化
ArrayList is a raw type. References to generic type ArrayList should be parameterized
但是我做不到
ArrayList<String> resultado_padre = new ArrayList();
因为这不是一个字符串数组列表,那么 bust 是什么类型的?
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
.List
接口更通用,因此在将变量声明为具体类型时,问问自己是否有必要这样做.看针对接口编程
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<E> 的引用应该参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文