Comparable interface analysis

xiaoxiao2021-03-06  59

Now look at the definition of the interface: public interface comparable {public int compareto (Object O);} The interface defines the natural order of the class, and you can sort this interface. General Requirements: E1.Equals Object) E2) and E2) E2) == 0 E2) == 0 Has the same value, so we are called the natural order as equally. What is the use of this interface? If data or List is implemented? In this interface, we can call Collections.Sort or the Arrays method to sort them.

If the natural order is inconsistent with Equals, if there is an expected logic error, you can't add it when you call Add, and you don't have this element in the collection. Specific discussion to interface mych Application of the table.

转载请注明原文地址:https://www.9cbs.com/read-118617.html

New Post(0)