Saturday, February 14, 2009
Getting Integer and Long System Properties in Java
In the learn-something-new-every-day department, in a code review this week for one of the developers on my team, I noticed that he was calling Integer.getInteger(). I had never seen this before. Turns out that this method and its overloads get system properties as Integers, handling the numeric conversion for you and returning null if it fails. There is also a Long.getLong() that does the same thing for (you guessed it) Longs. So all of those times I called System.getProperty() followed by Integer.parseInt() with a catch of NumberFormatException, I was doing WAY too much work. Good to know.