即使超类实现相同的接口,在子类中实现接口也有任何好处

问题描述:

当我看到声明 ArrayList

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

实现列表接口,即使 ArrayList 的超类 AbstractList 实现了相同的列表接口。

which implements List interface even though ArrayList's superclass AbstractList implements the same List interface.

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

类似的声明可以在 HashMap 上找到, LinkedHashMap 声明也是。

Similar declarations can be found on HashMap, LinkedHashMap declarations also.

LinkedHashMap 的声明中,它仅实现 Map 接口而不是其他接口由超类 HashMap 实现的接口。

In the declaration of LinkedHashMap, it implements Map interface only and not the other interfaces implemented by its superclass HashMap.

所以这样的声明可能有一些好处。

So there might be some benefits of having such declarations.

再次声明它们没有任何功能上的好处,它不会以任何方式影响行为。

There are no functional benefits to declaring them again, it does not affect the behavior in any way.

我想这只是为了更清楚地说明实现了哪些接口。

I guess it's only added to make it clearer which interfaces are implemented.