当我将Enum实例变量设置为包含在Enum类本身中作为选项的值时,无法将其解析为类型。为什么?

问题描述 投票:0回答:1
//Enum class

package model.cards;

public enum Rarity {
      BASIC, COMMON, RARE, EPIC, LEGENDARY}

//Different class

package model.cards.minions;
import model.cards.Rarity;

public class Icehowl {
    private int manaCost=9;
    private Rarity rarity=LEGENDARY; //error "LEGENDARY" can not be resolved to a variable
    private boolean attacked=true;
    private int maxHP=10;
}
java enums instance
1个回答
0
投票

您的意思

private Rarity rarity = Rarity.LEGENDARY;

枚举值LEGENDARY是类型Rarity中的常数。

© www.soinside.com 2019 - 2024. All rights reserved.