Andy Xiao
Andy Xiao

Reputation: 109

How do I dynamically invoke non-class methods in Groovy?

def greet() {
    println "Hello, Groovy!"
}

greet() // How to call this function dynamically?

Upvotes: 0

Views: 225

Answers (1)

tim_yates
tim_yates

Reputation: 171194

Assuming you mean you want to call it by name:

def greet() {
    println "Hello Groovy!"
}

def name = "greet"

"$name"()

Should work

Upvotes: 3

Related Questions