为什么 new Formatter().format("%h", false) 得到 4D5?
Why new Formatter().format("%h", false) gets 4D5?
根据输出,java boolean false 等于 10011010101
,true 等于 4CF,10011001111
。我不明白为什么 java 将这些值用作布尔值。究竟存储了什么布尔值?
%h
格式说明符的文档:
If the argument arg is null
, then the result is "null"
. Otherwise, the result is obtained by invoking Integer.toHexString(arg.hashCode())
.
我认为这不言自明。 false
被装箱到 Boolean.FALSE
中,并且该对象恰好具有哈希码。
根据输出,java boolean false 等于 10011010101
,true 等于 4CF,10011001111
。我不明白为什么 java 将这些值用作布尔值。究竟存储了什么布尔值?
%h
格式说明符的文档:
If the argument arg is
null
, then the result is"null"
. Otherwise, the result is obtained by invokingInteger.toHexString(arg.hashCode())
.
我认为这不言自明。 false
被装箱到 Boolean.FALSE
中,并且该对象恰好具有哈希码。