2

Considering definition of classes ArrayList and AbstractList in the package java.util

public class ArrayList<E> extends AbstractList<E>
        implements List<E>, RandomAccess, Cloneable, java.io.Serializable

public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E>

It's clear that when AbstractList implements List and ArrayList extends AbstractList, then implicitly ArrayList implements List.

What is the purpose of explicit clause implements List in ArrayList definition?

diziaq
  • 6,881
  • 16
  • 54
  • 96

1 Answers1

1

When working with the source code, this allows to see immediately which interfaces does the class implement.

Of course, it is also possible to figure this from the source code of the parent class, but having direct declaration saves the need of looking there (or into JavaDoc). This may be more important when the inherited interface is very high in the hierarchy and may require to review multiple parent classes before it can be found, when the source code of the parent class is not available or when the interface in question is the important part of the contract and must stay implemented even after the parent class no longer supports it.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93