How (not) to extend standard collection classes
Today in ##java, someone had a problem: They wanted a bounded-size PriorityQueue. One solution offered was extending the PriorityQueue class to add this behavior1. This article will talk about why that is not a good solution. Here is an example implementation of this approach: public class BoundedPriorityQueue<E> extends PriorityQueue<E> { private final int bound; public BoundedPriorityQueue(Comparator<? super E> comparator, int bound) { super(comparator); this.bound = bound...
Oct 24, 2017 — 7 minute(s) read