英文:
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
我已经阅读了许多文章,但它们说,应该导入java.util.List,而不是java.awt.List,但是我已经导入了。
有人可以帮忙看看我漏掉了什么吗?
英文:
I have imported java.util.List interface.
trying to create a function as follow:
public List<JSONObject,JSONArray> 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
我明白这里的问题。这是你正在做的事情。让我们通过下面的示例来理解这个问题。
这就是你在编译时遇到的相同错误。所以基本上你在处理列表时出了一些问题。列表只能存储单个元素,但你放了两个元素(键和值)。因此,Map 是存储这种类型值的数据结构。下面的屏幕截图是你的答案。希望现在你明白了。
英文:
I understand the problem here. This is what you are doing. Let's understand this by the below example.
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论