Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

android - ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized

I have this Method():

  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
}

And Lint return me the error:

ArrayList is a raw type. References to generic type ArrayList should be parameterized

But i cant do

ArrayList<String> resultado_padre = new ArrayList();

Because this isnt a arraylist of strings, what type bust will be?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could try creating the same type you are returning:

List<HashMap<String, String>> = new ArrayList<HashMap<String, String>>();

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...