java - What isn't comparable by the Comparable class? -
I know that this class compares two objects in a class (for example two strings), but its use How are the comparisons not class?
Basically, you can compare everything in Java.
For example, you have a class For example, it does not make sense to compare the colors This is correct though it does not make sense, you can Are there. Here is the answer to the question: Which color is bright? X , which is incomparable, you can create this attribute on another class
C and < Code> C , it can override its
compare () method.
Public class ComparableColor implements Comparable & lt; ComparableColor & gt; {Color color; Public Comparison Color (Color Color) {this.color = color; } Compare @ Override Public Int (Comparative Caller C) {return c.color.getAlpha () - this.color.getAlpha (); }}
Comments
Post a Comment