3

Possible Duplicate:
Cannot create an array of LinkedLists in Java…?

I want to call this method:

executeBatch(Map<String,Object>[] batch) 

But for the life of me I can't figure out how to create an array of Map<String,Object>[]

I get the error "Can create a generic array of HashMap" when I try HashMap<String,Object>[] params = new HashMap<String,Object>[20000];

I also failed at attempting to cast an ArrayList.toArray() to a HashMap<String,Object>[]

Community
  • 1
  • 1
David Parks
  • 30,789
  • 47
  • 185
  • 328

2 Answers2

14

You really cant. You have to do it like this:

@SuppressWarnings("unchecked")
HashMap<String, Object>[] map = new HashMap[20000];
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
4

Or with a more barbaric solution you can compile adding:

-Xlint:unchecked
vbence
  • 20,084
  • 9
  • 69
  • 118