Top Description Constructors Methods
com.google.common.base

public final Class Objects

extends ExtraObjectsMethodsForWeb
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, java.util.Arrays, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.Nullable

Helper functions that can operate on any Object.

See the Guava User Guide on writing Object methods with Objects.

Author
Laurence Gonsalves
Since
2.0

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean
equal(Object a, Object b)

Determines whether two possibly-null objects are equal.

public static int
hashCode(@Nullable Object... objects)

Generates a hash code for multiple values.

Constructor Detail

Objectsback to summary
private Objects()

Method Detail

equalback to summary
public static boolean equal(Object a, Object b)

Determines whether two possibly-null objects are equal. Returns:

  • true if a and b are both null.
  • true if a and b are both non-null and they are equal according to Object#equals(Object).
  • false in all other situations.

This assumes that any non-null objects passed to this function conform to the equals() contract.

Note for Java 7 and later: This method should be treated as deprecated; use java.util.Objects#equals instead.

hashCodeback to summary
public static int hashCode(@Nullable Object... objects)

Generates a hash code for multiple values. The hash code is generated by calling Arrays#hashCode(Object[]). Note that array arguments to this method, with the exception of a single Object array, do not get any special handling; their hash codes are based on identity and not contents.

This is useful for implementing Object#hashCode(). For example, in an object that has three properties, x, y, and z, one could write:

public int hashCode() {
  return Objects.hashCode(getX(), getY(), getZ());
}

Warning

When a single object is supplied, the returned hash code does not equal the hash code of that object.

Note for Java 7 and later: This method should be treated as deprecated; use java.util.Objects#hash instead.