This article describes the static Main method in groovy. First look at the following code:
class Test1 {
public Test1() {
println "TEST1"
}
}
class Test2 {
public Test2() {
println "TEST2"
}
static void main(args) {
new Test1()
}
}
This code does not run with either the Groovy command line or the Groovyconsole, as if it were a reference
Groovy.lang.MissingMethodException:No signature of Method:Test1.main () is applicable for argument types: ([ljava.lang.s Tring;) values: {[]}
At Test1.invokemethod (SCRIPT0)
And take a look at the new code:
class Test2 {//含有static void main的方法的Test2必须要在第一个定义
public Test2() {
println "TEST2"
}
static void main(args) {
new Test1()
}
}
class Test1 {
public Test1() {
println "TEST1"
}
}
The meaning of this is needless to say:
In groovy scripts, there should be no classes that define multiple static main methods. If you have more than one class defined, you should put the class with the main method in the first place;D
These are the static main methods in the groovy script file.