You are breaking a contract with comparable ones.
Actually, you do not compare two objects between them, but you only compare the field of the valuecurrent object TestObjectin accordance with the result modulo 3. You do not use the object TestObjectpassed as a parameter in the method compareTo().
, List TestObject 3 value
-1:
if (value % 3 == 0) {
return -1;
}
:
sgn (x.compareTo(y)) == -sgn (y.compareTo(x)) x y. ( , x.compareTo(y) iff y.compareTo(x) .)
, x, y.
y.compareTo(x) (, -1), x.compareTo(y) (, 1).
Comparable , IllegalArgumentException, = 50 , size = 5
, Comparable, . , .
JVM .
, , , .
, , .
, . API.