• 枚举


    1、简单

    public enum Signal {
      GREEN, YELLOW, RED
    }
    

      

    2、复杂

    public enum Color {
    	RED("红色", 1), GREEN("绿色", 2), BLANK("白色", 3), YELLO("黄色", 4);
    	private String name;
    	private int index;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public int getIndex() {
    		return index;
    	}
    
    	public void setIndex(int index) {
    		this.index = index;
    	}
    
    	private Color(String name, int index) {
    		this.name = name;
    		this.index = index;
    	}
    	public static Color getColor(int index) {
    		Color result = null;
    		Color [] colors = values();
    		for(int i=0;i<colors.length;i++) {
    			Color color = colors[i];
    			if(color.index == index) {
    				result = color;
    				break;
    			}
    		}
    		return result;
    	}
    }
    

      

    3、接口

    public interface FeedBackConstant {
    
    	enum Type{
    		IPHONE(0,"iphone"),ANDROID(1,"android"),IPAD(2,"android"),ANDROID_PAD(3,"androidpad");
    		int index;
    		String name;
    		public int getIndex() {
    			return index;
    		}
    		public void setIndex(int index) {
    			this.index = index;
    		}
    		public String getName() {
    			return name;
    		}
    		public void setName(String name) {
    			this.name = name;
    		}
    		private Type(int index, String name) {
    			this.index = index;
    			this.name = name;
    		}
    
    		public static Map<String,Object> generateEnumMap() {
    			Map<String,Object> resultMap = new HashMap<String,Object>();
    			Type [] typeArr = values();
    			for(int i=0;i<typeArr.length;i++) {
    			Type type = typeArr[i];
    			resultMap.put(Integer.toString(type.getIndex()), type.getName());
    			}
    			return resultMap;
    		}
    	}
    
    	enum FeedBackType{
    
    	}
    }
    

      

  • 相关阅读:
    图片文件重命名
    MySql基础学习-Sql约束
    MySql基础学习-库表操作
    java内存模型
    数据库常用函数整理
    linux用户管理
    Db2数据库在Linux下的安装和配置
    图像金字塔
    特征值与特征向量
    齐次线性方程组
  • 原文地址:https://www.cnblogs.com/lichangyunnianxue/p/9603088.html
Copyright © 2020-2023  润新知