Re: Somewhere in this constructor of PriorityBlockingQueue is hard to understand
Liu via Concurrency-interest <[email protected]> Wed, 5 Aug 2020 10:12:14 +0800 (CST)
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <[email protected]> |
"ArrayList<Holder> al = new ArrayList<>(2);" should be "ArrayList<Holder> al = new ArrayList<>();", be the way. At 2020-08-05 10:07:29, "Liu" <[email protected]> wrote: import java.util.ArrayList; import java.util.Queue; import java.util.concurrent.PriorityBlockingQueue; public class test16 { static class Holder implements Comparable<Holder> { int i; Holder(int i) { this.i = i; } public int compareTo(Holder h) { if(h == null) return -1; return this.i - h.i; } } public static void main(String[] args) { ArrayList<Holder> al = new ArrayList<>(2); al.add(new Holder(1)); al.add(new Holder(2)); al.add(null); Queue a = new PriorityBlockingQueue<>(al); } } In this case, heapify() cound not find null item. _______________________________________________ Concurrency-interest mailing list [email protected] http://cs.oswego.edu/mailman/listinfo/concurrency-interest