//好难翻译啊
Many methods in Collections Framework interfaces are defined in terms of the equals
method. For example, the specification for the containsKey(Object key)
method says: "returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.equals(k))." This specification should not be construed to imply that invoking Map.containsKey with a non-null argument key will cause key.equals(k) to be invoked for any key k. Implementations are free to implement optimizations whereby the equals invocation is avoided, for example, by first comparing the hash codes of the two keys. (The Object.hashCode()
specification guarantees that two objects with unequal hash codes cannot be equal.) More generally, implementations of the various Collections Framework interfaces are free to take advantage of the specified behavior of underlying Object
methods wherever the implementor deems it appropriate
集合框架接口中许多方法是被定义的(但如何定义看个人行为(自己补充的)),拿equals方法来说,我们可以自己去定义它。我们还可以举个例子,containsKey(Object key)方法的定义是说“返回为true,如果并且只要这个这个map包含了键值为k,例如((key==null ? k==null : key.equals(k))。”,这个定义不应该解释说明为调用非空参数的keyMap.containsKey方法将会导致key.equals(k)会被调用对于任何键值k。实现(Implementations)是自由地去实现优化即你可以不用调用equals方法来实现。例如,首先可以通过比较两个键值的hash码(解释不多说)。通常情况下,实现者只要认为它是合适的,不同集合框架接口的实现是自由利用底层对象方法的特定行为的。