getBoolean(String str) and valueOf(String str) of Boolean class gives different output(Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出)
问题描述
我很惊讶地知道 getBoolean()
和 valueOf()
方法对相同的输入字符串返回不同的结果.
I am surprised to know that getBoolean()
and valueOf()
method returns different results for the same input string.
我已尝试将 "true"
传递给这两种方法.但是 getBoolean()
给了我错误的输出,而 valueOf()
给了我正确的输出是正确的.为什么?
I have tried to pass the "true"
to both the methods. But getBoolean()
gives me false output whereas valueOf()
gives me right output that is true. Why?
推荐答案
API 文档是您的朋友.
The API-documentation is your friend.
Boolean.getBoolean
可能不会像您认为的那样:
Boolean.getBoolean
probably doesn't do what you think it does:
当且仅当 system由参数命名的属性存在且等于字符串true".
Boolean.valueOf
可能就是你要找的:
Boolean.valueOf
is probably what you're looking for:
如果字符串参数不为空并且等于字符串true",则返回的布尔值表示值 true.
这篇关于Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出


基础教程推荐
- 多个组件的复杂布局 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01