table.add(row); // Line #1
If you see the Line #1, table.add(row); It directly means we want table
to be something where we could add a List itself; Each element of the table
would be a List itself. Till now what you saw is, each element of list being
Integer, String, Animal,Dog or so. List is also an object so it can also
be an element of the List.
Each object (List) added to the "table" would be holding Integer objects.
So we have
List<List<Integer>> table = new ArrayList<List<Integer>>();
It can't be
List<List<Integer>> table = new ArrayList<
ArrayList<Integer>>();
Because you want to add List and List can't be added to where ArrayList
is needed. This is only applicable when you write
ArrayList<Integer> row = new ArrayList<Integer>();
Polymorphism applies to base type. If List is required you can pass
ArrayList but vice versa is not true.
Thanks,
[ May 15, 2007: Message edited by: Chandra Bhatt ]