java.lang.Boolean有一个
Boolean getBoolean(String)方法。
如果没有用过这个方法或者只看方法名,很容已让人误解这个方法将一个字符串转换成Boolean对象。既然不是将字符串参数转换成Boolean对象,那这个方法到底干什么用呢。看代码,让你大吃一惊:
public static boolean getBoolean(String name) {
boolean result = false;
try {
result = toBoolean(System.getProperty(name));
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
}
return result;
}
private static boolean toBoolean(String name) {
return ((name != null) && name.equalsIgnoreCase("true"));
}