Why does this not compile : List<List<String>> lss = new ArrayList<ArrayList<String>>();

Viewed 536

The below code :

List<List<String>> lss = new ArrayList<ArrayList<String>>();

causes this compile time error :

Type mismatch: cannot convert from ArrayList<ArrayList<String>> to List<List<String>>

to fix I change the code to :

List<ArrayList<String>> lss = new ArrayList<ArrayList<String>>();

Why is this error being thrown ? Is this because the generic type List in List<List<String>> is instantiated and since List is an interface this is not possible ?

3 Answers
Related