gpt4 book ai didi

java - 枚举正在尝试通过不存在的公共(public)初始化程序来初始化自身

转载 作者:行者123 更新时间:2023-12-01 08:02:01 24 4
gpt4 key购买 nike

我有一个枚举、布局。我使用私有(private)初始值设定项定义了一些成员(不记得正确的术语)。由于某种原因,它声称“布局是抽象的;无法实例化'(Intellij Idea)。我声明的私有(private)初始化程序显示一条警告,表示它从未使用过。代码:

public static enum Layout {
CHARGE("Charge", false, false),

FESS("Fess", true, true),

PALE("Pale", true, true),

QUARTERLY("Quarterly", true, false),

PARTY_PER_PALE("Party per pale", true, false),

BORDURE("Bordure", true, false),

PARTY_PER_BEND_SINISTER("Party per bend sinister", true, false),

SCARPE("Scarpe", true, false),

THREE("Three", false, false),

COUNTERCHARGED("Countercharged", false, false);

public final String name;
public final boolean hasSecondary;
public final boolean chargeInSecondary;

public abstract String blazon(CoatOfArms paramCoatOfArms);

public abstract void draw(CoatOfArms paramCoatOfArms, MyDraw paramMyDraw, double paramDouble1, double paramDouble2, double paramDouble3);

public abstract void drawLayout(MyDraw paramMyDraw, double paramDouble1, double paramDouble2);

private Layout(String name, boolean hasSecondary, boolean chargeInSecondary) {
this.name = name;
this.hasSecondary = hasSecondary;
this.chargeInSecondary = chargeInSecondary;
}
}

最佳答案

由于您在 enum 中声明了 abstract 方法,因此它被认为是 abstract (就像抽象类),这就是为什么您不能实例化它。您也不能将其声明为静态!

固定枚举:

public enum Layout {
CHARGE("Charge", false, false),

FESS("Fess", true, true),

PALE("Pale", true, true),

QUARTERLY("Quarterly", true, false),

PARTY_PER_PALE("Party per pale", true, false),

BORDURE("Bordure", true, false),

PARTY_PER_BEND_SINISTER("Party per bend sinister", true, false),

SCARPE("Scarpe", true, false),

THREE("Three", false, false),

COUNTERCHARGED("Countercharged", false, false);

public final String name;
public final boolean hasSecondary;
public final boolean chargeInSecondary;

private Layout(String name, boolean hasSecondary, boolean chargeInSecondary) {
this.name = name;
this.hasSecondary = hasSecondary;
this.chargeInSecondary = chargeInSecondary;
}
}

关于java - 枚举正在尝试通过不存在的公共(public)初始化程序来初始化自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24729390/

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