A Java ‘aha!’ moment

Okay, so I’ve been programming Java since, what, 1997 or so? Just today I found a call that’s been there since version 1.0.2: Boolean.getBoolean(String). It’s shorthand for crap like this, which is what I’ve always written instead:

String propStr = System.getProperty("foo");
if (propStr != null && Boolean.valueOf(propStr)) { ... }

How can I have missed this?

Leave a Reply