Random access in ArrayDeque

Martin Buchholz martinrb at google.com
Fri Feb 7 20:24:44 UTC 2014


On Fri, Feb 7, 2014 at 11:46 AM, David M. Lloyd <david.lloyd at redhat.com>wrote:

> On 02/07/2014 12:59 PM, Martin Buchholz wrote:
>
>>
>> ArrayDeque should not actually implement List itself, because the change
>> in contract/behavior for hashCode/equals would be too great.
>>
>
> Extending ArrayList to implement Deque might avoid this?  Though I suppose
> the chance of exciting new conflicts "in the wild" is higher given that
> ArrayList has been around since 1.2.
>
>
I would have preferred a world where there was only one ArrayList class
that implemented the circular array idea of ArrayDeque, but it seems too
late.  Even today I would support circular-array-ification of ArrayList,
and ArrayList can compatibly implement Deque I think, but we're unlikely to
be able to reach consensus on that.  Applications have learned that
ArrayList is append-only, and so adding circular array mechanics would add
a small cost on all operations.  Which is probably why it wasn't done back
in 1.6.



>
>  But we can provide a List asList() method.
>>
>
> If this path is chosen, it could be perhaps interesting to have ArrayList
> and ArrayDeque act as mutual views for each other, though I'd hate to
> require the extra object when (as LinkedList shows) it is conceptually OK
> to implement List and Deque.
>
>
You can extend a List to implement Deque, but not the other way around.



More information about the core-libs-dev mailing list