Wednesday, November 4, 2009

The Autobox of Death

Hmm, maybe I should have another blog for Java geeking. What happened was, I had an ArrayList and for a variety of reasons I decided to turn it into a HashMap. After I’d fixed everything up, I got the weirdest NullPointerException, and I traced it to a call that looked like (x is the HashMap)

if ((x.size() > 0) && x.get(0).equals(foo))

and somehow the compiler had decided that get(0) was a reasonable thing to do to a HashMap. Uh, strong typing, anyone?

No comments: