Eva*_*van 2 java string-formatting
我确信之前已被问过,但我找不到答案.
Boolean nullValue = null;
Boolean falseValue = false;
System.out.println( String.format( "%b %b", nullValue, falseValue ) );
Run Code Online (Sandbox Code Playgroud)
这个"假错误"的输出怎么样?这正是我在机器上得到的东西.Java 8. Mac.Java noob.
编辑
所以这是预期的行为.它看起来不像Boolean toString产生我想要的输出null,false,true的行为.每个想要这个的人都应该自己写一个方法吗?是否有产生该输出的功能?
如果查看方法java.util.Formatter.FormatSpecifier.printBoolean(Object),只有变量为true才打印"true" - 否则打印为false.
在前面的StackOverflow问题中已经介绍了这一点.此行为在文档中指定.
| 归档时间: |
|
| 查看次数: |
264 次 |
| 最近记录: |