Guava.Objects.hashCode vs Java.Objects.hashCode

In Java 8, there is a java.util.Objects class that contains the hashCode() method. At the same time, Google Guava 19 contains com.google.common.base.Objects , which also has a hashCode() method.

My questions:

  • Is there a reason why I should prefer Guava 19 hashCode() over Java 8?
  • Can I fully rely on Java 8 hashCode() or is it better to stay with Guava?
+5
source share
1 answer

Guava Method Precedes Java 7.

A Java method with the same name takes only one argument. But sibling java.util.Objects.hash() takes a variable number of arguments, like Guava Objects.hashCode() .

If you are using Java 7 or later, you can use java.util.Objects.hash(...) . Guava documentation notes the following:

Note for Java 7 and later: this method should be considered deprecated; use Objects.hash (java.lang.Object ...) instead.

If you are using Java 6 or earlier, you can use the Guava method.

+13
source

Source: https://habr.com/ru/post/1245868/


All Articles