简体   繁体   English

蚂蚁java编译抛出找不到符号

[英]ant java compile throwing cannot find symbol

I am working on a project that is having a layered Architecture. 我正在一个具有分层体系结构的项目中。 I have a interface ABC and in that interface I have a enum XYZ 我有一个界面ABC,在那个界面中我有一个XYZ枚举

For ex 对于前

public interface ABC {
     public enum XYZ {
         CONSTANT1("SOMETHING"),
         CONSTANT2("SOMETHING3");
         final String name;

         private TYPE(String name) {
            this.name=name;
         }

         public String getName() {
            return this.name;
         }
     }
}

I am compiling this using ant and using this jar file in other layer. 我正在使用ant编译此文件,并在其他层中使用此jar文件。 In that layer I am trying to access it like 在那一层,我试图像

String name=ABC.XYZ.CONSTANT1.getName();

I am getting symbol not found error during compile. 编译期间出现符号未找到错误。 I verified classpath is set properly. 我确认classpath设置正确。 I am using ant v 1.8 and java 1.6. 我正在使用ant v 1.8和Java 1.6。

Why I am getting this error ? 为什么我收到此错误?

First of all, don't nest the enum in an interface. 首先,不要将枚举嵌套在接口中。 It's perfectly fine that it has its own source file named after the enum. 拥有以枚举命名的自己的源文件非常好。

Second, I assume you mean XYZ instead of TYPE in your private constructor? 其次,我假设您是在私有构造函数中使用XYZ而不是TYPE

Last, you should be able to use it in that way, no matter if compiled via ant or within eclipse or directly using javac. 最后,无论是通过ant还是在eclipse中进行编译,或者直接使用javac进行编译,您都应该能够以这种方式使用它。 Probably you have not compiled everything - the way you did it, there should be ABC.class (the interface), ABC$XYZ.class (the inner enum) and the class file of your calling class. 可能您尚未编译所有内容-这样做的方式,应该有ABC.class (接口), ABC$XYZ.class (内部枚举)和调用类的类文件。

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

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