ArrayList.java中List接口的冗余实现 [英] Redundant implementation of List interface in ArrayList.java

查看:1057
本文介绍了ArrayList.java中List接口的冗余实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

为什么ArrayList有implements List?

我是新的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.

我的两个假设是:


  1. 这是因为历史原因。
  2. c $ c> 是-a List< E> (这可能是关于 ArrayList 的唯一最重要的事情)。
  1. It's there for historic reasons. However, I can't find any evidence to support this.
  2. It's included for documentation purposes, to make it immediately clear than an ArrayList<E> is-a List<E> (this is probably the single most important thing to know about ArrayList).

这篇关于ArrayList.java中List接口的冗余实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆