Java 常提到的自然序(Natural Ordering)
阿新 • • 發佈:2018-05-18
相同 compare 布爾值 sta any ole com lang only
Natural Ordering常在容器中被提到,和叠代器一起出現。
在Comparable接口的API規範中找到了描述。
(https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html)
The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C.
Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false.
即對於類C的任意實例對象e1和e2,表達式“e1.compareTo(e2) == 0”與另一個表達式“e1.equals(e2) ”返回相同的布爾值。
Java 常提到的自然序(Natural Ordering)