We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
代码示例:
public enum StatusEnum { CREATING(0), PUBLISHED(1), FINISHED(2); private final int status; StatusEnum(int status) { this.status = status; } public int getStatus() { return status; } private static final Map<Integer, StatusEnum> mapper = new HashMap<>(3); static { Arrays.stream(StatusEnum.values()).forEach( statusEnum -> mapper.put(statusEnum.getStatus(), statusEnum) ); } /** * 将status值转为枚举. */ public static StatusEnum fromStatus(final Integer status) { if (status == null) { return null; } return mapper.get(status); } }
枚举的实现原理是:
public static final
fromStatus
The text was updated successfully, but these errors were encountered:
No branches or pull requests
代码示例:
枚举的实现原理是:
public static final
的字段fromStatus
的调用导致StatusEnum类加载,而类加载后枚举字段已被初始化完毕,所以这样是行得通的The text was updated successfully, but these errors were encountered: