先看如下代码:
此代码不论用groovy命令行还是用groovyConsole来运行都要出错,好像是
[quote]groovy.lang.MissingMethodException: No signature of method: Test1.main() is applicable for argument types: ([Ljava.lang.String;) values: {[]}
at Test1.invokeMethod(Script0)
[/quote]
再来看看新的代码:
其中的含义不用多说了吧:
[list]
[*]在groovy脚本里,不应该有定义多个static main方法的类
[*]如果有定义多个类,那么应该将有main方法的类放到第一位 ;D
[/list]
class Test1 {
public Test1() {
println "TEST1"
}
}
class Test2 {
public Test2() {
println "TEST2"
}
static void main(args) {
new Test1()
}
}
此代码不论用groovy命令行还是用groovyConsole来运行都要出错,好像是
[quote]groovy.lang.MissingMethodException: No signature of method: Test1.main() is applicable for argument types: ([Ljava.lang.String;) values: {[]}
at Test1.invokeMethod(Script0)
[/quote]
再来看看新的代码:
class Test2 {//含有static void main的方法的Test2必须要在第一个定义
public Test2() {
println "TEST2"
}
static void main(args) {
new Test1()
}
}
class Test1 {
public Test1() {
println "TEST1"
}
}
其中的含义不用多说了吧:
[list]
[*]在groovy脚本里,不应该有定义多个static main方法的类
[*]如果有定义多个类,那么应该将有main方法的类放到第一位 ;D
[/list]