While I was solving leetcode, I tried this code but gave me an error.


List<List<Integer>> al = new ArrayList<ArrayList<Integer>>();

and I was surprised, because

List<Integer> al = new ArrayList<Integer>();

works perfectly.

So I looked up in stack overflow https://stackoverflow.com/questions/24796273/incompatible-types-list-of-list-and-arraylist-of-arraylist

and figured out that this was not supposed to work.

It is also in JavaDocs

Long story short,

We should do

List<<List<Integer>> al = new ArrayList<List<Integer>>();

or

List<<List<Inteer>> al = new ArrayList();