asullaherc asullaherc - 2 months ago 8
Groovy Question

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

Answer
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

Comments