Math.abs("str".hashCode())
上面代码片段,返回的一定是正数吗?
答案是:不一定,当String#hashCode
返回Integer.MIN_VALUE
时,Math.abs返回的将也是Integer.MIN_VALUE
。
至于String#hashCode方法为什么返回负数,请参考:hashCode返回负数?
Math.abs("str".hashCode())
上面代码片段,返回的一定是正数吗?
答案是:不一定,当String#hashCode
返回Integer.MIN_VALUE
时,Math.abs返回的将也是Integer.MIN_VALUE
。
至于String#hashCode方法为什么返回负数,请参考:hashCode返回负数?