groovy创建类的问题
niaodanwangzi
2012-11-22
用groovy创建类,通过groovy脚本调用类中方法时报错:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, xxxx/xxx.groovy: 11: Invalid duplicate class definition of class groovy.xxx : The source xxxx/xxx.groovy contains at last two defintions of the class groovy.xxx. One of the classes is a explicit generated class using the class statement, the other is a class generated from the script body based on the file name. Solutions are to change the file name or to change the class name. @ line 11, column 8. public class xxx{ ^ 1 error 貌似是创建了两个名字相同的类,groovy在使用时会自动将对应的脚本创建成对应的类吗?这样的话脚本中再创建类是不是不能再使用文件名做类名? 我修改了类名,还是不行: startup failed, script1000001.groovy: 34: unable to resolve class 新类名 求指教,groovy到底是怎么工作的? |
|
niaodanwangzi
2012-11-24
已经找到问题原因 是文件编码的问题 详见
http://www.groovyq.net/content/%E4%BD%93%E9%AA%8Cgradle%EF%BC%881%EF%BC%89%EF%BC%9A%E5%88%9B%E5%BB%BA%E4%BD%A0%E7%9A%84groovy%E5%B7%A5%E7%A8%8B |