Which one of Queue's subclasses is a 'plain ordinary' queue?
相关问题
- Caugth ClassCastException in my Java application
- Ada beginner Stack program
- Parsing a Chemistry Formula in Python
- pass by reference in assembly
- Why is there no queue in Cocoa?
相关文章
- How to send parameters to queues?
- Threading in C# , value types and reference types
- Stack<> implementation in C#
- Java, Printing the stack values
- Python utilizing multiple processors
- Is there a stack space for every thread?
- How to customize blocking behavior of BlockingQueu
- How to implement a queue in a linked list in c?
(1) java.util.Stack is a legacy class from Java 1.0. It predates the Collections framework by many years, and it's frankly an example of horrible design on many fronts. Nothing about it is the way things should be. The main problem is that
Stack
extendsVector
, and as all inheritance in Java is public inheritance, all the methods ofVector
are available onStack
as well. Therefore, you can inspect any position in a Stack, add and remove elements from the middle, clear it, or do any number of other things that should not be part of a stack abstraction, without a cast. Contrast that to using theQueue
orDeque
interfaces, through which only stack-appropriate methods are available.(2) There really is no such thing as a plain ordinary queue, but LinkedList implements Queue without any special semantics, so maybe that's what you want.
Any of its concrete subclasses can be used as a "plain ordinary" queue. True, they may have additional functionality, but you're free to use only the methods declared in the
Queue
interface. Though I imagine you might want to avoid the subclasses whose extra functionality affect queue ordering (likePriorityQueue
), capacity, etc. if you want an "ordinary" one.