gpt4 book ai didi

java - Maven 编译器插件错误 : can't access enum (bad signature, bad class)

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:33:11 25 4
gpt4 key购买 nike

我正在使用 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 是 enum 并且看起来像这样:

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

更新 2:

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

更新 3:现代编译器也会显示 bad classbad signature 错误

最佳答案

终于找到答案了

错误在构造函数中:

ContentType(@NotNull 字符串标题...

枚举中的构造函数中不能有注释,因为 javac 有问题。Javac 为 enum 构造函数存储不正确的签名(您编写的签名,而不是实际使用的签名——我记得它有两个额外的参数)。当 javac 验证签名时,它会看到 annotated 参数,在我的例子中是 first 参数。但是在actual 签名中(String name, int ordinal, String title, CoreType coreType, boolean hasJad, String[] searchKeywords,两个第一个参数由枚举添加 -> 枚举翻译)title只是第三个参数,第一个参数是name没有注释 并且 javac 认为类不正确。

tl;dr 从构造函数中删除注解,javac 有问题

关于java - Maven 编译器插件错误 : can't access enum (bad signature, bad class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28152412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com