 Greeter {
def name
Greeter(who) {
name = who[0].toUpperCase() + who[1..-1]
}
def salute() { println "Hello ${name}!" }
}
g = new Greeter('world') // create object
g.salute() // Output "Hello World!"
Leveraging existing Java libraries:
import org.apache.commons.lang.WordUtils
class Greeter {
def name
Greeter(who) { name = WordUtils.capitalize(who) }
def salute() { println "Hello ${name}!" }
}
g = new Greeter('world') // create object
g.salute() // Output "Hello World!"
On the command line:
groovy -e "println 'Hello ' + args[0]" World
Enjoy making your code groovier !!!!
If you wish to stay up-to-date with our vibrant community, you can learn more about:
And below, you will find the latest announcements: