这两个代码片段有什么区别?
片段 1:
Object o = new Object();
int i = Objects.hashCode(o);
片段 2:
Object o = new Object();
int i = o.hashCode();
最佳答案
容忍空值
唯一的区别是如果 o 为 null,Objects.hashCode(o)
返回 0 而 o.hashCode()
会抛出一个 NullPointerException
.
关于java - Objects.hashCode() 和 new Object().hashCode() 的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16187453/