The expression is reported if it's free of side effects and its result is always the same (in terms of Object.equals()
).
The examples of such expressions are a + b
, Math.max(a, b)
, a.equals(b)
,
s.substring(a,b)
. To make sure the result is always the same, it's verified that the variables used in the expression don't
change their values between the occurrences of the expression.
Such expressions may contain methods of immutable classes like String
, BigDecimal
, etc,
and of utility classes like Objects
, Math
(except random()
).
The well-known methods, such as Object.equals()
, Object.hashCode()
, Object.toString()
,
Comparable.compareTo()
, and Comparator.compare()
are OK as well because they normally don't have
any observable side effects.
New in 2018.3