为什么 Java String.format null Boolean false 的输出以及如何将 String.format 改为 null?

Why is the output of Java String.format null Boolean false and how to String.format as null instead?

我确定以前有人问过这个问题,但我找不到答案。

Boolean nullValue = null;
Boolean falseValue = false;
System.out.println( String.format( "%b %b", nullValue, falseValue ) );

这个"false false"的输出如何?这正是我在我的机器上得到的。 Java8.Mac。 Java 菜鸟。

编辑

所以这是预期的行为。它看起来不像 Boolean toString 产生我想要的输出 null、false、true 的行为。每个想要这个的人都应该自己写一个方法吗?是否有产生该输出的函数?

如果您查看方法 java.util.Formatter.FormatSpecifier.printBoolean(Object),它只会在变量为 true 时打印 "true" - 否则打印 false。

进一步看,这已在之前的 Whosebug question 中介绍。此行为在文档中指定。