...
This will execute the autogenerated main(String[] args) method in the bytecode which instantiates the Foo class, which extends the
| Wiki Markup |
|---|
{link:Script|http://groovy.codehaus.org/apidocs/groovy/lang/Script.html}{link} |
...
There's no need to use a Binding if you don't want to; Foo will have a no-argument constructor as well. Though using a Binding you can easily pass in variables. After the end of the script any variables created will be in the Binding for you to access in Java.
...
If you just want to write some simple scripts and need some simple functions you can declare functions without writing a class.
One difference from normal class-based groovy is that the def keyword is required to define a function outside of a class.
Here's an example of a simple script with a function. Note that if ever you need things like static or instance variables and so forth then maybe its time to actually write a class ![]()
...