Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Operator

Method

a == b

a.equals(b) or a.compareTo(b) == 0 **

a != b

! a.equals(b)

a <=> b

a.compareTo(b)

a > b

a.compareTo(b) > 0

a >= b

a.compareTo(b) >= 0

a < b

a.compareTo(b) < 0

a <= b

a.compareTo(b) <= 0

** Note: The == operator doesn't always exactly match the .equals() method. You can think of them as equivalent in most situations. In situations where two objects might be thought "equal" via normal Groovy "coercion" mechanisms, the == operator will report them as equal. The .equals() method will not do so if doing so would break the normal rules Java has around the equals method.

Notes about operations

Also in Groovy comparison operators handle nulls gracefully. So that a == b will never throw a NullPointerException whether a or b or both are null.

...