Package 

Class ObjectsCompat


  • 
    public class ObjectsCompat
    
                        

    This class consists of static utility methods for operating on objects.

    • Method Summary

      Modifier and Type Method Description
      static boolean equals(@Nullable() Object a, @Nullable() Object b) Returns {@code true} if the arguments are equal to each otherand {@code false} otherwise.
      static int hashCode(@Nullable() Object o) Returns the hash code of a non-{@code null} argument and 0 for a {@code null} argument.
      static int hash(@Nullable() Array<Object> values) Generates a hash code for a sequence of input values.
      static String toString(@Nullable() Object o, @Nullable() String nullDefault) Returns the result of calling {@code toString} on the first argument if the first argumentis not {@code null} and returns the second argument otherwise.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • equals

         static boolean equals(@Nullable() Object a, @Nullable() Object b)

        Returns {@code true} if the arguments are equal to each otherand {@code false} otherwise.

        Consequently, if both arguments are {@code null}, {@code true} is returned and if exactly one argument is {@code null}, {@code * false} is returned. Otherwise, equality is determined by usingthe equals method of the firstargument.

        Parameters:
        a - an object
        b - an object to be compared with {@code a} for equality
      • hashCode

         static int hashCode(@Nullable() Object o)

        Returns the hash code of a non-{@code null} argument and 0 for a {@code null} argument.

        Parameters:
        o - an object
      • hash

         static int hash(@Nullable() Array<Object> values)

        Generates a hash code for a sequence of input values. The hash code is generated as if allthe input values were placed into an array, and that array were hashed by calling hashCode.

        This method is useful for implementing hashCode on objects containingmultiple fields. For example, if an object that has three fields, {@code x}, {@code y}, and {@code z}, one could write:

        @Override public int hashCode() {
            return ObjectsCompat.hash(x, y, z);
        }
        
        Warning: When a single object reference is supplied, the returned value does not equal thehash code of that object reference. This value can be computed by calling hashCode.
        Parameters:
        values - the values to be hashed
      • toString

        @Nullable() static String toString(@Nullable() Object o, @Nullable() String nullDefault)

        Returns the result of calling {@code toString} on the first argument if the first argumentis not {@code null} and returns the second argument otherwise.

        Parameters:
        o - an object
        nullDefault - string to return if the first argument is {@code null}