<qhelp>

<overview>

If two identical expressions are compared (that is, checked for equality or inequality), this is typically an indication of a mistake, because the Boolean value of the comparison is always the same. Often, it indicates that the wrong qualifier has been used on a field access.

An exception applies to inequality (`!=`) and equality (`==`) tests of a floating point variable with itself: the special floating point value `NaN` ("not-a-number") is the only value that is not considered to be equal to itself. Thus, the test `x != x` where `x` is a `float` or `double` variable is equivalent to checking whether `x` is `NaN`, and similarly for `x == x`.

</overview> <recommendation>

It is never good practice to compare a value with itself. If you require constant behavior, use the Boolean literals `true` and `false`, rather than encoding them obscurely as `1 == 1` or similar.

If an inequality test (using `!=`) of a floating point variable with itself is intentional, it should be replaced by `Double.isNaN(...)` or `Float.isNaN(...)` for readability. Similarly, if an equality test (using `==`) of a floating point variable with itself is intentional, it should be replaced by `!Double.isNaN(...)` or `!Float.isNaN(...)`.

</recommendation> <example>

In the example below, the original version of `Customer` compares `id` with `id`, which always returns `true`. The corrected version of `Customer` includes the missing qualifier `o` in the comparison of `id` with `o.id`.

</example> <references>

- Help - Eclipse Platform: Java Compiler Errors/Warnings Preferences.
- Java Language Specification: 15.21.1. Numerical Equality Operators.
</references> </qhelp>