Why this does not compile: List <List <String>> lss = new ArrayList <ArrayList <String>> ();
Code below:
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 does this error occur? Is it because the generic type instance is List<List<String>>created and since List is an interface, is this not possible?
+4
3 answers
From http://docs.oracle.com/javase/tutorial/java/generics/inheritance.html
. A B (, Integer),
MyClass<A>MyClass<B>, , A B.MyClass<A>MyClass<B>- .

+3