Dies ist eine alte Version des Dokuments!
Not yet useful!
Shebang:
#!/usr/bin/env groovy println "Hallo Sandy!"
A script automatically creates a class which has the same name as the filename of the script:
#!/usr/bin/env groovy // Filname: groovytest println this.class // prints: class groovytest println getClass() // prints: class groovytest println this.getClass() // prints: class groovytest
The first version is a class literal. println
seems to call implizitely toString()
on any object. (This is the same as System.out.println()
in standard java.):
println this.class // prints: class groovytest println this.class.toString() // prints: class groovytest
The parent class of the autogenerated script class is groovy.lang.Script
:
println this.class.getSuperclass() // prints: groovy.lang.Script
println()
is a method of the autogenerated script class (inherited from groovy.lang.Script
). It can be called without this.
and braces. This seems to be added automatically, because the following call prints: …Exception: No signature of method: groovytest.println() is applicable for argument types: (java.lang.Integer, java.lang.Integer)…
#!/usr/bin/env groovy // Filename: groovytest println 0,0
#!/usr/bin/env groovy myList = [1976, 1969] // create a list myList << 2010 // append something to the end println myList // => [1976, 1969, 2010] println myList[2] // => 2010 println myList[3] // => null println myList.size // => 3 println myList.class // => class java.util.ArrayList
Each list creates an implementation of java.util.List. Hence the complete API of List is available:
println myList.get(0) // => 1976 println myList.size() // => 2
More on lists: usage examples, added methods to standard List
def
?