zoukankan      html  css  js  c++  java
  • 枚举类规范

    package junit;
    /**
     * 枚举类
     * @author pengYi
     *
     */
    public class ColorEnum {
    	
    	private static final String CODE_RED = "1";
    	private static final String CODE_YELLOW = "2";
    	private static final String CODE_GREEN = "3";
    	
    	public static final ColorEnum RED = new ColorEnum(CODE_RED,"红色");
    	public static final ColorEnum YELLOW = new ColorEnum(CODE_YELLOW,"黄色");
    	public static final ColorEnum GREEN = new ColorEnum(CODE_GREEN,"绿色");
    	
    	private String code;
    	private String name;
    	
    	private ColorEnum(String code, String name) {
    		this.code = code;
    		this.name = name;
    	}
    	
    	/**
    	 * 返回枚举类对象
    	 * @param code
    	 * @return
    	 */
    	public static ColorEnum getColorByCode(String code) {
             if (code==null || "".equals(code)) {
                return null;
              } switch (code) { case CODE_RED : return RED; case CODE_YELLOW : return YELLOW; case CODE_GREEN : return GREEN; default : throw new IllegalArgumentException("请核对输入参数"); } } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }

      需要注意是:构造方法是私有的,防止外部调用,保证枚举类数据不被破坏

  • 相关阅读:
    C++怎么实现线程安全
    Linux内核之进程地址空间
    Linux内核之内存管理
    内存管理之内存寻址
    Linux内核初探
    进程间通信
    下拉列表控件实例 ComboBoxControl
    数据表格控件 DataGridControl
    8 种百度云高速下载,你值得拥有
    10 快好用的下载工具,终于和迅雷说拜拜了
  • 原文地址:https://www.cnblogs.com/py1994/p/6923261.html
Copyright © 2011-2022 走看看