Java中枚举的简单示例

  • Post author:
  • Post category: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;
	}
}



版权声明:本文为luoyeguigen000原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。