Why LinkedList
and ArrayList
延伸AbstractList
in Java?
当我们想要在实现类中指定公共行为时,可以使用抽象类。
但是里面的所有方法AbstractList
被覆盖ArrayList
and LinkedList
.
那么扩展这个类有什么用呢?
subList(int,int) https://docs.oracle.com/javase/7/docs/api/java/util/AbstractList.html#subList(int,%20int)
方法不被两者覆盖ArrayList
and LinkedList
,并且为此AbstractList
提供了一个通用的实现
来自Java源代码
public List<E> subList(int fromIndex, int toIndex) {
return (this instanceof RandomAccess ?
new RandomAccessSubList<E>(this, fromIndex, toIndex) :
new SubList<E>(this, fromIndex, toIndex));
}
此外,还有其他未被覆盖的方法,例如toString()
and iterator() http://docs.oracle.com/javase/1.4.2/docs/api/java/util/AbstractList.html#iterator%28%29
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)