getBoolean(String str) and valueOf(String str) of Boolean class gives different output

后端 未结 5 1957
野性不改
野性不改 2020-12-29 18:38

I am surprised to know that getBoolean() and valueOf() method returns different results for the same input string.

I have tried to pass the

5条回答
  •  萌比男神i
    2020-12-29 19:16

    Boolean.getBoolean must be the worst placed method in java. One of the big WTF.

    Why wasn't it placed in System or Properties or whatever?

    So to answer your question - yes, it is a very confusing thing and you can just click on the method in your IDE to see the code or read the javadoc.

    Here's the source code:

     public static boolean getBoolean(String name) {
            boolean result = false;
            try {
                result = toBoolean(System.getProperty(name));
            } catch (IllegalArgumentException e) {
            } catch (NullPointerException e) {
            }
            return result;
        }
    

提交回复
热议问题