在 Oracle tutorial about Collection
interfaces ,接口(interface)层次结构表明 Deque
直接扩展 Collection
。
但是 Deque
扩展了 Queue
(在 Java 版本中这种关系似乎没有变化)。
为什么这没有反射(reflect)在层次结构图中(例如,以 SortedSet
扩展 Set
的方式显示)?
最佳答案
取自 The Deque Interface - The Java™ Tutorials :
<小时/>The Deque interface is a richer abstract data type than both Stack and Queue because it implements both stacks and queues at the same time.
你是对的,Deque
确实扩展了Java中的Queue
...
但即使这种实际关系存在,我认为在这张图中省略它的要点是,从概念上讲,Deque
不仅可以被视为 Queue
的特化>.
Deque
为您提供了 Stack
的后进先出原则和 Queue
提供的先进先出,仅表示这些类和接口(interface)的严格实际层次结构可能会产生误导。
例如,LinkedList
实现了 Deque
...但是,您可能永远不会将其放在解释不同类型的架构上的 Deque
下。 集合
以及它们之间的关系。 :)
关于java - Collections 层次结构中的 Deque 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26338309/