zoukankan      html  css  js  c++  java
  • 常量 枚举区别

     

    一直纠结 ,貌似枚举能用的地方.常量都能实现.

    public static final int GROUP_MASTER = 1;

    public static final int GROUP_VICE_MASTER = 1;

    public static final int GROUP_NORMAL = 1;

    public static final String GROUP_MASTER_NAME = "会长";

    public static final String GROUP_VICE_MASTER_NAME = "副会";

    public static final String GROUP_NORMAL_NAME = "会员";

    public enum GroupPurviewType {
        /**
         * 工会会长
         */
        MASTER(1,1,"族长"),
        /**
         * 副会长
         */
        VICE_MASTER(4,2,"副会长"),
        /**
         * 普通会员
         */
        NORMAL(8,3,"会员");
        private int type = 0;
        private int order = 0;
        private String name = "";
        private GroupPurviewType(int type,int order ,String name)
        {
            this.type = type;
            this.order = order;
            this.name = name;
        }
        public int getValue()
        {
            return this.type;
        }
        public String getName()
        {
            return this.name;
        }
        public int getOrder()
        {
            return this.order;
        }
        public static GroupPurviewType parse(int val)
        {
            for(GroupPurviewType t : values()){
                if(t.getValue() == val)
                    return t; 
            }
            return NORMAL;
        }
        /**
         * 判断是否是在权限中.
         * @param val
         * @return
         */
        public static boolean exist(int val)
        {
            for(GroupPurviewType t : values()){
                if(t.getValue() == val)
                    return true;
            }
            return false;
        }
    }

    很自然,枚举会更加的简洁明了.   而且枚举支持  == 比较  switch case 等操作.  而且可以自己封装方法.  所以个人认为枚举确实好一些.

  • 相关阅读:
    10.14 正睿做题笔记
    斯坦纳树
    django+uwsgi+nginx 前后端分离部署配置
    pandas 取 groupby 后每个分组的前 N 行
    使用 Java SDK 获取 MaxCompute 的表结构并写入到 Excel 中
    PPYOLO模型参数配置理解
    分子表面计算库MSMS的linux安装教程
    使用Python的seaborn画热力图heatmap以及将两个矩阵合并画热图的方法
    常见图片格式分析-bmp,png
    BUUOJ-Misc刷题笔记
  • 原文地址:https://www.cnblogs.com/qiunet/p/3296448.html
Copyright © 2011-2022 走看看