41

In the Collection Framework we have the interface List and the class AbstractList:

AbstractList implements List

And ArrayList extends AbstractList and

implements List

My question: why does ArrayList have the implements List clause?

If ArrayList extends AbstractList and AbstractList implements List, can't we say, that ArrayList implement List?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
user471011
  • 7,104
  • 17
  • 69
  • 97

3 Answers3

53

Yes. It could've been omitted. But thus it is immediately visible that it is a List. Otherwise an extra click through the code / documentation would be required. I think that's the reason - clarity.

And to add what Joeri Hendrickx commented - it is for the purpose of showing that ArrayList implements List. AbstractList in the whole picture is just for convenience and to reduce code duplication between List implementations.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 29
    Not only that, but I prefer this style because it is intention-revealing. The goal of arraylist is to implement List. Extending abstractlist is just a way of achieving that goal. – Joeri Hendrickx Dec 08 '10 at 12:42
  • @Joeri Hendrickx agreed. +1 for the comment – Bozho Dec 08 '10 at 12:47
  • If the base class implements an interface, the current JavaDoc tool (both Oracle's and the Gnu version) will list that the derived class implements the interface automatically, without your putting `implements TheInterface` on the derived class. So no extra clicks required. (This is true even if the base class is not public.) – T.J. Crowder Dec 11 '15 at 14:53
8

My 2 cents is to keep to the fact that ArrayList is a List. AbstractList just completes certain implementations that the List requires.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
7

Most likely this is to increase tracability of the inheritance structure. That way you don't have to go down the whole inheritance tree, when browsing the Javadoc or the like.

Jules
  • 1,352
  • 7
  • 19