开发者

Java: How to create an array of Map<String,Object> objects [duplicate]

开发者 https://www.devze.com 2023-02-22 21:36 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Cannot create an array of LinkedLists in Java…?
This question already has answers here: Closed 11 years ago.

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>[]


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

@SuppressWarnings("unchecked")
HashMap<String, Object>[] map = new HashMap[20000];


Or with a more barbaric solution you can compile adding:

-Xlint:unchecked
0

精彩评论

暂无评论...
验证码 换一张
取 消