加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Maven编译器插件错误:无法访问枚举(错误签名,坏类)

发布时间:2020-12-15 04:45:08 所属栏目:Java 来源:网络整理
导读:我正在使用maven-compiler-plugin:2.3.2并且每当我在导入中具有枚举(ContentType)的类中进行更改时,我需要清理,否则它会给我: ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project
我正在使用maven-compiler-plugin:2.3.2并且每当我在导入中具有枚举(ContentType)的类中进行更改时,我需要清理,否则它会给我:

ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project wp2: Compilation failure
[ERROR] /home/semyon/development/.../ContentManager.java:[15,46] error: cannot access ContentType
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project wp2: Compilation failure
/home/semyon/development/.../ContentManager.java:[15,46] error: cannot access ContentType

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:364)
...

ContentType是枚举,如下所示:

import org.jetbrains.annotations.NotNull;

public enum ContentType {

    ...; 

    private final String title;

    private final boolean hasJad;

    private final CoreType coreType;

    private final String[] searchKeywords;



    ContentType(@NotNull String title,CoreType coreType,boolean hasJad,String[] searchKeywords) {
        this.title = title;
        this.coreType = coreType;

        this.hasJad = hasJad;
        this.searchKeywords = searchKeywords;
    }

    @NotNull
    public String getTitle() {
         return title;
    }

    @NotNull
    public String getName() {
        return name();
    }

    @NotNull
    public CoreType getCoreType() {
        return coreType;
    }

    public enum CoreType {

         ...;

        private String title;

        CoreType(String title) {
            this.title = title;
        }

        public String getTitle() {
            return title;
        }

    }
}

UPD1,项目结构:

/wp2
             /core
                  /cpe
                     /widget
                           /ContentManager.java
                  /cdr
                     /entities
                           /ContentType.java

UPD 2:

ContentManager.java:[15,46]是导入wp2.core.cdr.entities.ContentType;

UPD 3:
现代编译器也会显示错误的类和错误的签名错误

解决方法

我终于找到了答案

错误发生在costructor中:

ContentType(@NotNull字符串标题…

枚举中的构造函数不能包含注释,因为javac会被窃听.
Javac存储了枚举构造函数的错误签名(你写的那个,而不是实际使用的那个 – 我记得它有两个额外的参数).
当javac验证签名时,它会看到带注释的参数,在我的情况下,这是第一个参数.但是在实际签名中(String name,int ordinal,String title,String [] searchKeywords,两个第一个params由enum添加 – > Enum translation)title只是第三个参数,第一个参数是name没有注释,javac认为课程不正确.

tl; dr从构造函数中删除注释,javac是错误的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读