chikadance
chikadance

Reputation: 4177

MalformedParameterizedTypeException when use ArrayList<ArrayList<>>

Here is my code:

class TestDraft {
    ArrayList<ArrayList<String, Double>> a = []

    static void main(String[] args) {
        new TestDraft().a.add(["pr", 2])
    }
}

It raise:

"java.lang.reflect.MalformedParameterizedTypeException"

when I change ArrayList<ArrayList<String, Double>> to ArrayList it work, but I hope to what cause:

MalformedParameterizedTypeException

Upvotes: 0

Views: 174

Answers (1)

tim_yates
tim_yates

Reputation: 171144

ArrayList<ArrayList<Integer, Integer, Integer>>

doesn't make any sense (which I think is what the error is telling you)

It should just be:

ArrayList<ArrayList<Integer>>

To say that you have a list of lists of integers... Generics do not express how many elements are in a List

Upvotes: 1

Related Questions