Incorrect number of arguments for type List<E>; it cannot be parameterized with arguments <JSONObject, JSONArray>

huangapple go评论70阅读模式
英文:

Incorrect number of arguments for type List<E>; it cannot be parameterized with arguments <JSONObject, JSONArray>

问题

我已经导入了java.util.List接口。
尝试创建一个如下的函数:

public List<JSONObject,JSONArray> getDetail(String s)

但是它显示错误消息:
“类型List的参数数量不正确;无法使用<JSONObject,JSONArray>作为参数进行参数化”
我已经阅读了许多文章,但它们说,应该导入java.util.List,而不是java.awt.List,但是我已经导入了。
有人可以帮忙看看我漏掉了什么吗?

英文:

I have imported java.util.List interface.
trying to create a function as follow:

public List&lt;JSONObject,JSONArray&gt; getDetail(String s)

But it shows error as
"Incorrect number of arguments for type List<E>; it cannot be parameterized with arguments <JSONObject, JSONArray>"
I have gone through many articles but they said ,import java.util.List instead java.awt.List but i already imported that.
Can anyone help here what i am missing here ?

答案1

得分: 1

我明白这里的问题。这是你正在做的事情。让我们通过下面的示例来理解这个问题。

Incorrect number of arguments for type List<E>; it cannot be parameterized with arguments <JSONObject, JSONArray>

这就是你在编译时遇到的相同错误。所以基本上你在处理列表时出了一些问题。列表只能存储单个元素,但你放了两个元素(键和值)。因此,Map 是存储这种类型值的数据结构。下面的屏幕截图是你的答案。希望现在你明白了。

Incorrect number of arguments for type List<E>; it cannot be parameterized with arguments <JSONObject, JSONArray>

英文:

I understand the problem here. This is what you are doing. Let's understand this by the below example.

Incorrect number of arguments for type List<E>; it cannot be parameterized with arguments <JSONObject, JSONArray>

This is the same error you are getting at compile time. So basically you are doing something wrong with the List. List can only store single elements but you are putting 2 elements (key & value). So Map is the data structure to store this kind of value. Below screenshot is your answer. Hope this is clear to you now.

Incorrect number of arguments for type List<E>; it cannot be parameterized with arguments <JSONObject, JSONArray>

huangapple
  • 本文由 发表于 2020年8月31日 14:22:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63665781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定