RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)
Doug Lea
dl at cs.oswego.edu
Wed Aug 7 14:22:00 UTC 2013
On 07/25/13 10:15, Doug Lea wrote:
> On 07/24/13 19:30, Martin Buchholz wrote:
>> PriorityQueue is unusual in that Doug maintains a copy in jsr166 CVS even though
>> it is a non-thread-safe collection. I think it makes sense,
>> because PriorityQueue and PriorityBlockingQueue have parallel APIs and parallel
>> implementations. Many changes to one file require a matching change to the
>> other.
>>
>
> The history is that we introduced java.util.concurrent.PriorityBlockingQueue,
> for JDK1.5 which of course led to people wanting plain java.util.PriorityQueue,
> which Josh started working on while at Sun. But for sake of JCP approval,
> we pulled into jsr166 and have adopted ever since, because the two
> classes share code. The capacity constructor was added in JDK1.6,
> but I have no recollection why there is not one with comparator
> but no capacity. It seems reasonable to add one.
Now I remember. Or rather javac forces me to remember.
Adding this constructor breaks source compatibility:
[javac] /home/dl/concurrent/src/test/tck/PriorityBlockingQueueTest.java:97:
error: reference to PriorityBlockingQueue is ambiguous
[javac] new PriorityBlockingQueue(null);
[javac] ^
[javac] both constructor PriorityBlockingQueue(Comparator<? super E>) in
PriorityBlockingQueue and constructor PriorityBlockingQueue(Collection<? extends
E>) in PriorityBlockingQueue match
[javac] where E is a type-variable:
[javac] E extends Object declared in class PriorityBlockingQueue
I'm thinking to not include this at least in PriorityBlockingQueue.
-Doug
>
>
>> Regarding this particular change, if PriorityQueue gets a new constructor taking
>> a Comparator, then PriorityBlockingQueue probably should too
>
> Yes.
>
> *** PriorityBlockingQueue.java.~1.99.~ Wed Jul 24 11:23:05 2013
> --- PriorityBlockingQueue.java Thu Jul 25 10:13:47 2013
> ***************
> *** 200,205 ****
> --- 200,219 ----
> }
>
> /**
> + * Creates a {@code PriorityBlockingQueue} with the default
> + * initial capacity that orders its elements according to the
> + * specified comparator.
> + *
> + * @param comparator the comparator that will be used to order this
> + * priority queue. If {@code null}, the {@linkplain Comparable
> + * natural ordering} of the elements will be used.
> + * @since 1.8
> + */
> + public PriorityBlockingQueue(Comparator<? super E> comparator) {
> + this(DEFAULT_INITIAL_CAPACITY, comparator);
> + }
> +
> + /**
> * Creates a {@code PriorityBlockingQueue} containing the elements
> * in the specified collection. If the specified collection is a
> * {@link SortedSet} or a {@link PriorityQueue}, this
>
>
More information about the core-libs-dev
mailing list