ArrayList.java中List接口的冗余实现 [英] Redundant implementation of List interface in ArrayList.java
问题描述
我是新的java我试图看到集合接口的层次结构。我发现 AbstractList.java 的签名类似于
I am new to java I was trying to see the hierarchy of collection interface. I found that the signature of AbstractList.java is like
public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E>
它实现List接口。但是如果你看看子类ArrayList.java的签名,它看起来像
It implements List interface. But if you look at signature of child class ArrayList.java it looks like
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable
已经实现的List接口,那么为什么子类再次实现相同的接口( List )。
If you look parent class is already implemented List interface then why child class is again implementing same interface (List).
>
推荐答案
这
Is there specific reason or requirement behind this
我不这么认为。删除第二个 List< E>
对编译器来说绝对不会改变。
I don't think so. Removing the second List<E>
would change absolutely nothing as far as the compiler is concerned.
我的两个假设是:
- 这是因为历史原因。
c $ c> 是-a
List< E>
(这可能是关于 ArrayList
的唯一最重要的事情)。 - It's there for historic reasons. However, I can't find any evidence to support this.
- It's included for documentation purposes, to make it immediately clear than an
ArrayList<E>
is-aList<E>
(this is probably the single most important thing to know aboutArrayList
).
这篇关于ArrayList.java中List接口的冗余实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!