Hey,

The introduction of ArrayDeque in Java 1.6 has basically replaced LinkedList as the "default" implementation of java.util.Queue, which is probably for the best. However, from time to time, I still see use cases where a class that implements both Deque and List is wanted for ease of use. LinkedList is currently the only class that supports this. One example would be sorting the queue in-place.

Has there been any discussion on having ArrayDeque implement List?

There is no *technical* reason against doing so - the internal structure of ArrayDeque is fully capable of supporting an implementation of List, and there would be no additional fields needed that would change current memory behavior. The existing Deque interface would also remain unaffected.

I see two possible reasons against doing this:

- Added maintenance effort, a lot of it duplicated from ArrayList. This *could* be done gradually: ArrayDeque only extends AbstractCollection right now so implementations for e.g. subList could be inherited from AbstractList. Performance tweaking would be nice in many places though. - Design - conceptually, a Deque is something very different from a List. LinkedList implementing both could be seen as a mistake from that point of view. When coding to interfaces, which is good practice anyway, this change isn't visible though.

Thoughts?

- Jonas Konrad

Reply via email to