可以看到LinkedList implements Deque, 而ArrayList却没有。
另外还有一个ArrayDeque类。
为什么不让List接口继承Deque呢?
伊谢尔伦2017-04-17 11:43:37
Deque
inherits from Queue
. In fact, just think that List
does not inherit from Queue
. It is true that List
can easily use remove(Object o)
to implement Queue
's remove()
, but it is generally not designed this way because their meanings are different. Whether to use List
to implement Queue
is left to the specific class to decide. The answer for LinkedList
is yes, and for ArrayList
it is no.
As for why ArrayList
did not implement Queue
, this is because ArrayList
itself is just a List
covered in Array
skin. It is not recommended to insert new data from the top, otherwise the efficiency will be extremely poor. .
ArrayDeque
is a textbook deque implementation, and its existence is not controversial.