java - 当我将 Enum 实例变量设置为作为选项包含在 Enum 类本身中的值时,它无法解析为类型。为什么?
问题描述
//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;
}
解决方案
你的意思是
private Rarity rarity = Rarity.LEGENDARY;
枚举值LEGENDARY
是类型中的常量Rarity
。
推荐阅读
- python-3.x - 实际交互与模拟 MockService 的预期交互不匹配
- browserstack - 如何使用 browserstack 的本地功能仅测试最新的浏览器版本?
- git - Git rebase 错误的提交
- python-3.x - 如何在 tkinter 标签中使用 png 图像获得平滑边缘
- kdb - 每个组的 KDB 顶行
- pip - 使用 pip 安装模块失败
- angular-material - 在角材料表中绑定动态数据
- python - Odoo 10 - python 3 setup.py install got NameError: name 'execfile' is not defined
- javascript - 如何将字符串转换为具有锯齿状数组的数组
- c# - 将字符串转换为日期类型