The “use” mix-in in Groovy

Standard
Punch card from a typical Fortran program.

Image via Wikipedia

Here’s a code example:

Class StringMulti {
        static def multi(def self, args) {
        def z = self.toInteger()
        args.each{
            z *= it.toInteger()
        }
        return z
    }

}

use (StringMulti) {
        def y = ["343", "98", 98, 100]
        def x
        x = "1".multi y
        println x
}

The “use” mix-in allows the static methods of the class specified in use to be mixed in to the classes – with the first parameter of the mix in replacing self in the example above.