Groovy supports operator overloading which makes working with Numbers, Collections, Maps and various other data structures easier to use.

Various operators in Groovy are mapped onto regular Java method calls on objects. This allows you the developer to provide your own Java or Groovy objects which can take advantage of operator overloading. The following table describes the operators supported in Groovy and the methods they map to.

OperatorMethod
a + ba.plus(b)
a - ba.minus(b)
a * ba.multiply(b)
a / ba.divide(b)
a++ or ++aa.increment()
a-- or --aa.decrement()
a[b]a.get(b)
a[b] = ca.put(b, c)

Note that all the following comparison operators handle nulls gracefully avoiding the throwing of java.lang.NullPointerException

OperatorMethod
a == ba.equals(b)
a != b! a.equals(b)
a === ba == b in Java (i.e. a and b refer to same object instance)
a <=> ba.compareTo(b)
a > ba.compareTo(b) > 0
a >= ba.compareTo(b) >= 0
a < ba.compareTo(b) < 0
a <= ba.compareTo(b) <= 0