Then wouldn’t it be redundant to implement List as well as extend AbstractList?
Yes, it is 100% redundant. However, Java implementors added interfaces very consistently in all public implementation of the collections library:
LinkedList<E>
andArrayList<E>
extendAbstractList<E>
which implementsList<E>
, and then implementList<E>
themselves.HashSet<E>
andTreeSet<E>
extendAbstractSet<E>
which implementsSet<E>
, and then implementSet<E>
themselves.HashMap<K,V>
andTreeMap<E>
extendAbstractMap<K,V>
which implementsMap<K,V>
, and then implementMap<K,V>
themselves.
My understanding is that they did so for documentation purposes: the authors wanted to show that ArrayList<E>
is primarily a List<E>
; the fact that ArrayList<E>
extends AbstractList<E>
is a less significant detail of its implementation. Same goes for the other public collection types.
Note that Arrays.ArrayList<E>
class is not publicly visible, so its authors did not care to include List<T>
explicitly.
As far as the failed conversion goes, this should come as no surprise, because the inner class Arrays.ArrayList<E>
and the public class ArrayList<E>
are unrelated to each other.