Skip to content

Instantly share code, notes, and snippets.

@lucastanziano
Last active September 20, 2015 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucastanziano/e6274afa22a7bbd64886 to your computer and use it in GitHub Desktop.
Save lucastanziano/e6274afa22a7bbd64886 to your computer and use it in GitHub Desktop.
// Broken - Inappropriate use of inheritance!
public class InstrumentedHashSet<E> extends HashSet<E> {
// The number of attempted element insertions
private int addCount = 0;
public InstrumentedHashSet() {
}
public InstrumentedHashSet(int initCap, float loadFactor) {
super(initCap, loadFactor);
}
@Override public boolean add(E e) {
addCount++;
return super.add(e);
}
@Override public boolean addAll(Collection<? extends E> c) {
addCount += c.size();
return super.addAll(c);
}
public int getAddCount() {
return addCount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment