The implementation of java.util.ArrayList
implements List
as well as extends AbstractList
. But in java docs you can see that AbstractList already implements List. Then wouldn't it be redundant to implement List as well as extend AbstractList?
My second question
Please have a look at the following code :
String str = "1,2,3,4,5,6,7,8,9,10";
String[] stra = str.split(",");
List<String> a = Arrays.asList(stra);
The Arrays.asList()
method of the Arrays class contains its own implementation of ArrayList. But this one only extends AbstractList but does not implement List. But the above code compiles.
BUT when the code is modified to the following
String str = "1,2,3,4,5,6,7,8,9,10";
String[] stra = str.split(",");
java.util.ArrayList<String> a = Arrays.asList(stra);
I get an error : cannot convert form List<String> to ArrayList<String>
What is the reason behind this?
EDIT
Arrays.asList()
does return its own implementation of ArrayList. Check this out.