The Daily WTF
One of the key points of confusion for people unfamiliar with Java is the distinction between true object types, like Integer, and “primitive” types, like int. This is made worse by the collection types, like ArrayList, which needs to hold a true object type, but can’t hold a primitive. A generic ArrayList<Integer> is valid, but ArrayList<int> won’t compile. Fortunately for everyone, Java automatically “boxes” types- at least since Java 5, way back in 2004- so integerList.add(5) and int n = integerList.get(0) will both work just fine.
Somebody should have told that to Alice‘s co-worker, who spends a lot of code to do some type gymnastics that they shouldn’t have:
try { ps = conn.prepareStatement(SQL_GET_LOT_WORKUP_STATUSES); ps.setLong(1, _lotId); rs = ps.executeQuery(); while (rs.next()) { result.add(new Integer(rs.getInt(1))); } } finally { CloseUtil.close(ps,rs); } // instatiate a the array _workupStatuses = new int[result.size()]; // convert the integers to ints for (int h=0; h<result.size(); h++)
To read the full article click on the 'post' link at the top.