Groovy call method name contains special character
I would like to call a method whose name contains a space in a static context, but it doesn't work. Any suggestions?
class Test2 {
void "test"() {
"test a"()
}
void "test a"() {
println "test a"
}
public static void main(String[] args) {
def t = new Test2()
t."test"() //it works
t."test a"() //raise error, Illegal class name "Test2$test a" in class file Test2$test a
}
}
G:\tmp\groovy\gp1\src>groovy -version
Groovy Version: 2.3.2 JVM: 1.7.0_02 Vendor: Oracle Corporation OS: Windows 7
G:\tmp\groovy\gp1\src>groovy Test2.groovy
Test1.main
Caught: java.lang.ClassFormatError: Illegal class name "Test2$test a" in class file Test2$test a
java.lang.ClassFormatError: Illegal class name "Test2$test a" in class file Test2$test a
at Test2.main(Test2.groovy:15)
+3
source to share
2 answers