【发布时间】:2020-05-28 14:25:55
【问题描述】:
我创建了一个非常基本的枚举
public enum StatusCode {
OK(0, "Everything ran correctly"),
ERROR(4, "Fatal Error");
private final int value;
private final String description;
StatusCode(final int value, final String description) {
this.value = value;
this.description = description;
}
public int getValue() { return value; }
public String getDescription() { return description; }
}
在我的方法中,我试图返回一个整数
public Integer func() {
return StatusCode.OK; // Inside method
}
错误:
类型不匹配:无法从 StatusCode 转换为 Integer
我知道我可以做到StatusCode.OK.getValue(),但它看起来很奇怪。 StatusCode.OK怎么能默认为整数?
【问题讨论】:
-
"我知道我可以做 StatusCode.OK.getValue() 但它看起来很奇怪" 为什么? “StatusCode.OK怎么能默认为整数?”不能。
-
我不认为这看起来很奇怪。
标签: java