但行好事
莫论前程❤

java枚举工具类EnumUtils

public class EnumUtils{
    private static Map map = new HashMap();
    static{
        map.put("datastatus",Datastatus.class);
        map.put("billstatus",Billstatus.class);
    }

    public static String getLabel(Object obj, Short value){
        Class clazz = (Class)map.get(obj);
        if(clazz = null || value == null){
            return null;
        }
        try{
            Method method = clazz.getMethod("getLabel",Short.class);
            return (String)method.invoke(clazz,value);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static Short getShort(Object obj,String name){
        Class clazz = (Class)map.get(obj);
         if(clazz = null || value == null){
            return null;
        }
        try{
            Method method = clazz.getMethod("getShort",String.class);
            return (String)method.invoke(clazz,name);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        EnumUtils.getShort("datastatus","初始化");
        EnumUtils.getLabel("datastatus",1);
    }
}
赞(0) 打赏
未经允许不得转载:刘鹏博客 » java枚举工具类EnumUtils
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏