现在的code Sample很简单
public class Test {
public static void main(String[] args)
{
boolean isRMS = Boolean.getBoolean("true");
boolean isDW = Boolean.getBoolean("true");
System.out.println("isRMS="+isRMS);
System.out.println("isDW="+isDW);
}
}
按我们的常规理解,应该打印
isRMS=true
isDW=true
但是实际结果却是
isRMS=false
isDW=false
为何会这样,看了以下API文档,是这样解释的
getBoolean(String name)
Returns true if and only if the system property named by the argument exists and is equal to the string "true".不是很明白,所以又看了一下中文的
getBoolean(String name)
当且仅当以参数命名的系统属性存在,且等于 "true" 字符串时,才返回 true。那么问题关键就是“当且仅当以参数命名的系统属性存在”时如何理解了??
请大虾指教
public class Test {
public static void main(String[] args)
{
boolean isRMS = Boolean.getBoolean("true");
boolean isDW = Boolean.getBoolean("true");
System.out.println("isRMS="+isRMS);
System.out.println("isDW="+isDW);
}
}
按我们的常规理解,应该打印
isRMS=true
isDW=true
但是实际结果却是
isRMS=false
isDW=false
为何会这样,看了以下API文档,是这样解释的
getBoolean(String name)
Returns true if and only if the system property named by the argument exists and is equal to the string "true".不是很明白,所以又看了一下中文的
getBoolean(String name)
当且仅当以参数命名的系统属性存在,且等于 "true" 字符串时,才返回 true。那么问题关键就是“当且仅当以参数命名的系统属性存在”时如何理解了??
请大虾指教
public static boolean getBoolean(String name)当且仅当以参数命名的系统属性存在,且等于 "true" 字符串时,才返回 true。(从 JavaTM 1.0.2 平台开始,字符串的测试不再区分大小写。)通过 getProperty 方法可访问系统属性,此方法由 System 类定义。
如果没有以指定名称命名的属性或者指定名称为空或 null,则返回 false。
参数:
name - 系统属性名。
返回:
系统属性的 boolean 值。~~~~~~~~~~~~~~~
注意是“系统属性”
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String aa = "aa";
System.setProperty(aa,"true");
boolean isRMS = Boolean.getBoolean(aa);
boolean isDW = Boolean.getBoolean("true");
System.out.println("isRMS="+isRMS);
System.out.println("isDW="+isDW);
}
}
====================================
isRMS=true
isDW=false
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String aa = "true";
System.setProperty(aa,"true");
boolean isRMS = Boolean.getBoolean(aa);
boolean isDW = Boolean.getBoolean("true");
System.out.println("isRMS="+isRMS);
System.out.println("isDW="+isDW);
}
}
================================================================
isRMS=true
isDW=true
Boolean.parseBoolean("false")
那么转为boolean型,我就这样作
boolean isRMS = false;
boolean isDW = false;
if(userBean.getIsRMS().equalsIgnoreCase("true"))
{
isRMS=true;
}
if(userBean.getIsDW().equalsIgnoreCase("true"))
{
isDW=true;
}
java怎么搞得这样麻烦阿,还有什么简便方法吗??请大虾赐教
还有
Boolean.parseBoolean("true")
Boolean.parseBoolean("false")
根本语法就有问题阿
Boolean.parseBoolean("true")
Boolean.parseBoolean("false")
根本语法就有问题阿
=======================
你的jdk版本太低了吧
看过1.5知道什么范型,静态导入的东东
现在不用,又忘拉,只有这样的方法
Boolean.parseBoolean("true")
Boolean.parseBoolean("false")我还真是才疏学浅,不知阿
慢慢来
多查查api,
查多了就明白它的套路了
public class Test {
public static void main(String[] args)
{
boolean isRMS = Boolean.getBoolean("true");
boolean isDW = Boolean.getBoolean("true");
System.out.println("isRMS="+isRMS);
System.out.println("isDW="+isDW);
}
}放在另外一个类中它有时的结果又是正常的即打印
isRMS=true
isDW=true
我认为肯定是哪里不对,可是又找不到原因,估计还是什么低级错误???
有些晕