O'Reilly logo

Grails in Action, Second Edition by Glen Smith and Peter Ledbrook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Groovy reference

It’s not always easy to find the information you want about Groovy, so we’ve incorporated a short reference here that includes useful information in an easily digested form. It focuses on two Groovy features: operator overloading and the extension methods that Groovy adds to the core Java class library.

A.1. Operator overloading

Groovy allows you to support operators on your own classes, such as +, *, <<, and so on. The mechanism for this is straightforward: implement methods with specific names. If you want to support adding two matrices together with the + operator, you can implement plus():

class Matrix {
    ...
    Matrix plus(Matrix other) {
        ...
    }
}

Even if you don’t implement any of the operator methods yourself, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required