Stuff I Hate About Java

DefaultTable uses Vector, not list

"Has A" vs "Is A"

  1. Stack extends ArrayList
    Why does Stack extend ArrayList? It should probably be a LinkedList anyway. Presumably, there will be no indexed retrieval and ArrayList has the potential to eat far more space than it needs. Plus overhead of resizing. Cite Joshua Bloch admitting mistake.
  2. Properties extends Hashtable
    Properties should extend or encapsulate HashMap<String,String>


No need. Objects are sufficient

Exposed constructors for primitive wrappers

No need.


Cite Susan's letter.

LinkedHashSet from the end

Cite java forum note. Cite util override. Need last() and reverseIterator().

ArrayList not circular

CircularArrayLists sometimes perform much better that standard ArrayLists and never perform (much) worse. Why not make this default implementation?

Missing covariants

Where possible, an overriding method should return a more specific type.

Redundant Methods

NavigableMap/Set head/tail/sub map/set

Outdated Classes

Vector?, Hashtable, SortedMap, SortedSet, Enumeration, StringBuffer

Methods return null instead of empty array

JTree.getSelectedNodes(), JDesktopPane.getAllFrames(), TreeSet.comparator(), TreeMap.comparator()

Color Constants

Get rid of lowercase ones.

int constants should be enums

No local enums



Swing methods that return arrays. Do arrays even serve any purpose now? Generic lists serve the purpose.


Narrow returns.



ListModel should implement List

hashCode() makes it impossible to simultaneously implement List and Set


Why are width/height/x/y members exposed and different types from accessors.

AbstractDocument constants

Why not all caps?


BadLocationException is checked!?!

Covariant clone

clone() should return proper type.

Bad Mutability

java.awt.Dimension, java.awt.Insets, java.awt.Point, java.awt.Rectangle and java.util.Date should not be mutable.


Name threads.


Why do events have a type if methods differ?

navigable 'last' semantics

Concept of 'last' in NavigableMap.lastEntry() differs from that in SortedSet.last(). Should caller expect a null or an exception if collection is empty?

Generic wildcard handling

Wildcard type guessing is terrible. All wildcards should be known to extend Object. Wildcards should not be considered unequal if they have equivalent constraints.


There's a decent chance that a StringBuffer or StringBuilder is used only to create a String. Resultant String should use buffer's character array rather than creating a new copy. Buffer can lazily copy only if necessary.

Seemingly trivial tasks are difficult

  1. Open JDBC connection, get data and release resources
  2. Get text from a Document
  3. Get String from a stream

Too Many Primitives

float/double? short/int/long? Just pick a size and stick with it.


Nothing is guaranteed in terms of threading, timing or eventing. Also, no interface.

InputMap/ActionMap put

Should return old mapping.