Java:如何创建 Map<String,Object> 对象数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5577391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 11:44:51  来源:igfitidea点击:

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

javaarrays

提问by David Parks

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

可能的重复:
无法在 Java 中创建 LinkedList 数组……?

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

但是对于我的生活,我无法弄清楚如何创建一个数组 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];

我在尝试时收到错误“可以创建一个通用的 HashMap 数组” HashMap<String,Object>[] params = new HashMap<String,Object>[20000];

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

我也未能尝试将 an 转换ArrayList.toArray()为 aHashMap<String,Object>[]

回答by Lukas Eder

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

你真的不行。你必须这样做:

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

回答by vbence

Or with a more barbaric solution you can compile adding:

或者使用更野蛮的解决方案,您可以编译添加:

-Xlint:unchecked