Define a function

To define a function in a Groovy script use

def sayHello(name){
    return 'Hello, ' + name
}
println sayHello('Groovy')

To define a function in a Groovy class use

class Greeting {
    def sayHello(name) {
        return 'Hello, ' + name
    }
}
 
def greet = new Greeting()
println greet.sayHello('Groovy')
You can leave a response, or trackback from your own site.

Leave a Reply