src/share/classes/java/util/Objects.java

Print this page




 102     * array, and that array were hashed by calling {@link
 103     * Arrays#hashCode(Object[])}.
 104     *
 105     * <p>This method is useful for implementing {@link
 106     * Object#hashCode()} on objects containing multiple fields. For
 107     * example, if an object that has three fields, {@code x}, {@code
 108     * y}, and {@code z}, one could write:
 109     *
 110     * <blockquote><pre>
 111     * &#064;Override public int hashCode() {
 112     *     return Objects.hash(x, y, z);
 113     * }
 114     * </pre></blockquote>
 115     *
 116     * <b>Warning: When a single object reference is supplied, the returned
 117     * value does not equal the hash code of that object reference.</b> This
 118     * value can be computed by calling {@link #hashCode(Object)}.
 119     *
 120     * @param values the values to be hashed
 121     * @return a hash value of the sequence of input values
 122     * @see Arrays#hashCode
 123     * @see List#hashCode
 124     */
 125     public static int hash(Object... values) {
 126         return Arrays.hashCode(values);
 127     }
 128 
 129     /**
 130      * Returns the result of calling {@code toString} for a non-{@code
 131      * null} argument and {@code "null"} for a {@code null} argument.
 132      *
 133      * @param o an object
 134      * @return the result of calling {@code toString} for a non-{@code
 135      * null} argument and {@code "null"} for a {@code null} argument
 136      * @see Object#toString
 137      * @see String#valueOf(Object)
 138      */
 139     public static String toString(Object o) {
 140         return String.valueOf(o);
 141     }
 142 




 102     * array, and that array were hashed by calling {@link
 103     * Arrays#hashCode(Object[])}.
 104     *
 105     * <p>This method is useful for implementing {@link
 106     * Object#hashCode()} on objects containing multiple fields. For
 107     * example, if an object that has three fields, {@code x}, {@code
 108     * y}, and {@code z}, one could write:
 109     *
 110     * <blockquote><pre>
 111     * &#064;Override public int hashCode() {
 112     *     return Objects.hash(x, y, z);
 113     * }
 114     * </pre></blockquote>
 115     *
 116     * <b>Warning: When a single object reference is supplied, the returned
 117     * value does not equal the hash code of that object reference.</b> This
 118     * value can be computed by calling {@link #hashCode(Object)}.
 119     *
 120     * @param values the values to be hashed
 121     * @return a hash value of the sequence of input values
 122     * @see Arrays#hashCode(Object[])
 123     * @see List#hashCode
 124     */
 125     public static int hash(Object... values) {
 126         return Arrays.hashCode(values);
 127     }
 128 
 129     /**
 130      * Returns the result of calling {@code toString} for a non-{@code
 131      * null} argument and {@code "null"} for a {@code null} argument.
 132      *
 133      * @param o an object
 134      * @return the result of calling {@code toString} for a non-{@code
 135      * null} argument and {@code "null"} for a {@code null} argument
 136      * @see Object#toString
 137      * @see String#valueOf(Object)
 138      */
 139     public static String toString(Object o) {
 140         return String.valueOf(o);
 141     }
 142