rspec/rules/S2200/java/rule.adoc

22 lines
375 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
While most ``++compareTo++`` methods return -1, 0, or 1, some do not, and testing the result of a ``++compareTo++`` against a specific value other than 0 could result in false negatives.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
if (myClass.compareTo(arg) == -1) { // Noncompliant
// ...
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
if (myClass.compareTo(arg) < 0) {
// ...
}
----