Boolean.getBoolean(String s)看起来是将字符串主换成boolean型,但实际上并非如此。
以下是API文档:
public static boolean getBoolean(String name)
Returns true if and only if the system property named by the argument exists and is equal to the string "true". (Beginning with version 1.0.2 of the JavaTM platform,the test of this string is case insensitive.) A system property is accessible through getProperty, a method defined by the System class.
If there is no property with the specified name, or if the specified name is empty or null, then false is returned.
Parameters: name - the system property name.
Returns: the boolean value of the system property.
该方法是查找系统参数中是否有与name同名的参数,有则返回true;无则返回false。并非将name转型为boolean。想要转型,可以使用:
Boolean.parseBoolean(String s)
或
Boolean.valueOf(String s).booleanValue()
-------------------------------------原创内容,转载请说明出处-----------------------------------------
欢迎联系
微信:oscaryue001