简体   繁体   English

无法在groovyc中编译Java代码

[英]Couldn't able to compile Java code in groovyc

Hi I have a set of java classes which worked very fine when I compile them with javac command: 嗨,我有一组Java类,当我用javac命令编译它们时,它们工作得很好:

javac -g -nowarn -classpath /usr/class/cs143/cool/lib:.:/usr/java/lib/rt.jar ASTConstants.java ASTParser.java cool-tree.java 

I installed groovy on the same machine and tried to execute the following: 我在同一台机器上安装了Groovy,并尝试执行以下操作:

groovyc  -classpath /usr/class/cs143/cool/lib:.:/usr/java/lib/rt.jar ASTConstants.java ASTParser.java cool-tree.java 

It seems that groovy doesn't able to understand the java file and its throwing error like: 看来groovy无法理解java文件及其抛出错误,例如:

ASTParser.java: 21: unexpected token: protected @ line 21, column 3.
     protected static final short _production_table[][] = 
 ^

I'm bit confused. 我有点困惑。 Does that all java programs are valid groovy code? 那所有的Java程序都是有效的Groovy代码吗? Only the viceversa isn't true right? 反之亦然,不是吗?

Where I'm making the mistake? 我在哪里犯错?

Thanks in advance. 提前致谢。

There are some quirks. 有一些怪癖。 Used to be some issues with inner classes (may be resolved by now in 2.x), and you may have to watch what's in your String literals (stray dollar signs, for eg,). 过去曾经是内部类的一些问题(可能现在在2.x中已解决),并且您可能必须注意String文字中的内容(例如,美元符号)。 Using a literal for an array definition can be a problem (eg, int [] ary = {}; won't fly in groovy). 在数组定义中使用文字可能会是一个问题(例如, int [] ary = {};不会杂乱无章)。 Also, doesn't come up often, but scope braces used by themselves confuse groovy. 同样,它并不经常出现,但是它们自己使用的示波器大括号会混淆常规。

In your particular case, just change the short _production_table [][] to be short [][] _production_table . 在您的特定情况下,只需将short _production_table [][]short _production_table [][]更改为short _production_table [][] short [][] _production_table I believe that should clear your issue up. 我相信这应该可以解决您的问题。

BTW, some other "gotchas" here . 顺便说一句, 这里还有其他一些“陷阱”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM