task groovy << {} def foo = 6.5 println "foo has value. $foo" println "Let's do same math. 5 + 6 = ${5 + 6}" println "foo is of type: ${foo.class} and has value: $foo" foo = "a string" println "foo is new of type: ${foo.class} and has value: $foo"
[vagrant@localhost ud867]$ gradle groovy Hello Java! :groovy BUILD SUCCESSFUL Total time: 6.464 secs [vagrant@localhost ud867]$ gradle groovy foo has value. 6.5 Let's do same math. 5 + 6 = 11 foo is of type: class java.math.BigDecimal and has value: 6.5 foo is new of type: class java.lang.String and has value: a string :groovy BUILD SUCCESSFUL Total time: 6.531 secs
task groovy << {} def doubleIt(n){ n + n // Note we don't need a return statement } def foo = 5 println "doubleIt($foo) = ${doubleIt(foo)}" foo = "foobar" println "doubleIt($foo) = ${doubleIt(foo)}"
[vagrant@localhost ud867]$ gradle groovy doubleIt(5) = 10 doubleIt(foobar) = foobarfoobar :groovy BUILD SUCCESSFUL Total time: 6.396 secs