其实new Boolean(s).booleanValue()和Boolean.parseBool(s)是一个效果。。下面是Boolean类的部分代码。。。
/*
* @(#)Boolean.java 1.51 04/05/11
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package java.lang;
public final class Boolean implements java.io.Serializable,
Comparable<Boolean>
{
private final boolean value;
public Boolean(boolean value) {
this.value = value;
}
public Boolean(String s) {
this(toBoolean(s));
}
public boolean booleanValue() {
return value;
}
public static boolean parseBoolean(String s) {
return toBoolean(s);
}
private static boolean toBoolean(String name) {
return ((name != null) && name.equalsIgnoreCase("true"));
}
回复 更多评论