Interface Hasher


public interface Hasher
Hasher is intended to work like Comparable: it is an optional argument to a hashing data structure (such as some implementations of HashSet, HashMap, or WeakHashMap) which specifies the hashCode() and equals() methods.

If no Hasher is provided, then clients should act as if the following Hasher were provided:

   class DefaultHasher {
     int hashCode(Object o) { return o.hashCode(); }
     boolean equals(Object o, Object o2) { return o.equals(o2); }
   }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object o1, Object o2)
    The equality function over the objects being hashed.
    int
    hashCode function for objects under consideration (not for Hasher objects).
  • Method Details

    • hashCode

      int hashCode(Object o)
      hashCode function for objects under consideration (not for Hasher objects).
      Parameters:
      o - object whose hash code to compute
      Returns:
      o's hash code
    • equals

      boolean equals(Object o1, Object o2)
      The equality function over the objects being hashed.

      Has nothing to do with testing Hashers themselves for equality.

      Parameters:
      o1 - the first value to test for equality
      o2 - the second value to test for equality
      Returns:
      whether o1 equals o2