Archive for February, 2007

Integer.getInteger(), Boolean.getBoolean() etc.

Monday, February 5th, 2007

java.lang.System.getProperty() is a Java method to access a system property. The properties you can lookup are partly predefined, and others are set by tools or trough command-line parameters (-Dmyproperty=true). Because System is a class which deals with lots of system related things, Object-Orientation-wise it makes sense to put this responsibility (method) in this class.

But who was sleeping at the Java design team when someone sneaked in Integer.getInteger(String), Boolean.getBoolean(String) and alike? Completely counter-intuitive these method return a System property in Integer/Boolean form. I would have felt comfortable with something like System.getProperties().getBoolean(String), or System.getBooleanProperty(String), and I even could have lived with the legacy of a System.getBoolean(String) method, but not this. I’ve tripped in this myself (again) a short while ago, thinking that it was a method which would parse the String for me. I’ve seen other people make the same mistakes. From experience Java programmers know to use Integer.valueOf(String), but not because the method name makes so much more sense…

Isn’t this a great deprecation candidate for Java 5, 6 7?