package com.ruoyi.common.interfaces; import java.lang.reflect.Method; /** * 枚举接口,反射出枚举code对应的文本 或 文本对应的code * * @Author wangqiong * @Date 2023/01/5 * @Version V1.0 */ public interface EnumsInterface { static String getText(Class clazz, String code){ try { Method method = clazz.getMethod("getTextByCode", String.class); if(method!=null){ return (String)method.invoke(null,code); } }catch (Exception e){ System.err.println("getTextByCode方法不存在"); e.printStackTrace(); } return code; } static String getCode(Class clazz,String text){ try { Method method = clazz.getMethod("getCodeByText", String.class); if(method!=null){ return (String)method.invoke(null,text); } }catch (Exception e){ System.err.println("getCodeByText方法不存在"); e.printStackTrace(); } return text; } }