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

Viewed 1356

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; 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 Answers

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

enter image description here

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.

enter image description here

Related