错误未检查调用 'put(K, V)' 作为原始类型 'java.util.HashMap' 的成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25085054/
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-08-10 23:35:47  来源:igfitidea点击:

Error Unchecked call to 'put(K, V)' as a member of raw type 'java.util.HashMap'

javahashmaparraysjsonobject

提问by user3297875

I am getting the error

我收到错误

"Unchecked call to 'put(K, V)' as a member of raw type 'java.util.HashMap'"

“未经检查地调用 'put(K, V)' 作为原始类型 'java.util.HashMap' 的成员”

This is the line that shows the error

这是显示错误的行

JSONArray FieldValues = new JSONArray(new JSONObject(new HashMap().put(K, V)));

Am I doing anything wrong or is there something I should add? any help is greatly appreciated

我做错了什么还是我应该添加一些东西?任何帮助是极大的赞赏

采纳答案by bob0the0mighty

Looks like you are missing the types.

看起来你缺少类型。

Something like

就像是

new HashMap<Type1,Type2>().put(K,V)

should work.

应该管用。

回答by Chintan Shah

For anonymous use:

匿名使用:

new HashMap<Type1,Type2>().put(K,V);

For initializing a variable:

初始化变量:

HashMap<Type1,Type2> hashMap = new HashMap<>();
hashMap.put(K,V);

回答by Christian M. Salvatierra

It is not defined what type of data your HashMap will store. Example:

没有定义 HashMap 将存储什么类型的数据。例子:

Map<String, Object> hospedajeUpload = new HashMap<>();

In this example I assign the type String and Object.

在这个例子中,我分配了 String 和 Object 类型。