The “use” mix-in in Groovy

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()
            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.