Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...