Use Objects.hash() or own hashCode() implementation?

前端 未结 5 1570
清酒与你
清酒与你 2021-01-01 08:24

I have recently discovered the Objects.hash() method.

My first thought was, that this tidies up your hashCode() implementation a lot. See the following

5条回答
  •  灰色年华
    2021-01-01 09:10

    Joshua Bloch in his book Effective Java, 3rd edition, p. 53 discourages usage of Objects.hash(...) if performance is critical.

    Primitives are being autoboxed and there is a penalty of creating an Object array.

提交回复
热议问题