I am trying to solve a leetcode problem where I have a function and I am supposed to return a List of a List. eg. public List < List < Integer>> func(TreeNode root)
To solve this problem, I wish to create another function where I pass an empty List of List and eventually return this List of List as my answer.
List < List < Integer >> ret = new List < List < Integer >>();
However this leads to an error, List is abstract; cannot be instantiated.
If I change this to
ArrayList < ArrayList < Integer >> ret = new ArrayList < ArrayList <Integer > >();
I cannot convert the ArrayList < ArrayList < Integer > to List < List < Integer > >
.
I can't even get this to work.
List < List < Integer > > ret = new ArrayList < ArrayList < Integer > > ();
Can you suggest some way around this? I have been facing this kind of issue a lot of times and usually find some workaround to solve this. What is the proper method to resolve this?
>`. See https://stackoverflow.com/questions/2745265/is-listdog-a-subclass-of-listanimal-why-are-java-generics-not-implicitly-po.