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
  • 28,443
  • 44
  • 166
  • 295

2 Answers2

15

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

@SuppressWarnings("unchecked")
HashMap<String, Object>[] map = new HashMap[20000];
Lukas Eder
  • 196,412
  • 123
  • 648
  • 1,411
4

Or with a more barbaric solution you can compile adding:

-Xlint:unchecked
vbence
  • 19,714
  • 8
  • 64
  • 114