How does one instantiate an array of maps in Java?

后端 未结 8 1245
刺人心
刺人心 2020-11-30 06:34

I can declare an array of maps using generics to specify the map type:

private Map[] myMaps;

However, I can\'t figur

8条回答
  •  温柔的废话
    2020-11-30 06:58

    In general it is not a good idea to mix generics and arrays in Java, better use an ArrayList.

    If you must use an array, the best way to handle this is to put the array creation (your example 2 or 3) in a separate method and annotate it with @SuppressWarnings("unchecked").

提交回复
热议问题