google / guava

Google core libraries for Java
Apache License 2.0
50.19k stars 10.91k forks source link

Primitives feature request: variadic hashCode method #3206

Open Pr0methean opened 6 years ago

Pr0methean commented 6 years ago

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?

ben-manes commented 6 years ago

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.