Java中枚举的简单示例

public enum PaymentEnum {
	
	ONLINE_PAY(1, "在线支付"),
	CASH_ONLY(2,"现金支付");
	
	PaymentEnum(int code,String value) {
        this.code = code;
        this.value = value;
    }

	private String value;
	private int code;

	public String getValue() {
        return value;
    }

	public int getCode() {
		return code;
	}

	public static PaymentEnum codeOf(int code) {
		for (PaymentEnum paymentTypeEnum : values()) {
			if (paymentTypeEnum.getCode() == code) {
				return paymentTypeEnum;
			}
		}
		//throw new RuntimeException("没有有找到对应的枚举");
		return null;
	}
}

猜你喜欢

转载自blog.csdn.net/luoyeguigen000/article/details/80286102