Why LinkedList and arraylist extends AbstractList in java?

后端 未结 4 1375
一个人的身影
一个人的身影 2021-02-13 18:41

Why LinkedList and ArrayList extends AbstractList in Java?

Abstract classes are used when we want to specify a common beh

4条回答
  •  滥情空心
    2021-02-13 18:55

    subList(int,int) method is not overriden by both ArrayList and LinkedList, and for this AbstractList provides a common implementation

    From Java source

    public List subList(int fromIndex, int toIndex) {
            return (this instanceof RandomAccess ?
                    new RandomAccessSubList(this, fromIndex, toIndex) :
                    new SubList(this, fromIndex, toIndex));
        }
    

    In addition there are other methods which are not overriden like toString() and iterator()

提交回复
热议问题