It's often tempting to use java.util.Objects.hash to implement hashCode() for a POJO class. But if this is done with primitives, then it leads to unnecessary autoboxing and can hurt performance. Why not have Longs.hashCode(long... values) and so on for the other primitive types, with no boxing?
You still need to compose hashCodes when different types, so its less usable. You might prefer to use HashCodeBuilder from Apache Commons instead, which may not allocate thanks to escape analysis.
It's often tempting to use
java.util.Objects.hash
to implementhashCode()
for a POJO class. But if this is done with primitives, then it leads to unnecessary autoboxing and can hurt performance. Why not haveLongs.hashCode(long... values)
and so on for the other primitive types, with no boxing?