java枚举定义方式,字符串转枚举 ,枚举转字符串

2022-09-09 11:16:45

枚举定义

package com.scbd.bdpl.define.enumerate.code;import com.java.comn.assist.EnumDefine;import com.scbd.bdpl.support.annotation.AnnotationCodeType;/**
 * @author lp
 */publicenum STRimplementsEnumDefine<STR>{str("字段含义"),;private String description;private STR(String description){this.description= description;}@Overridepublic StringgetDescription(){return description;}}

字符串转枚举

String str="str";//定义枚举code
STR.valueof(str)//STR对应枚举对象

获取枚举对应字段中文

STR.str.getDescription()// =字段含义

枚举转字符串

STR.str.toString()// =str

枚举占用计算机内存,建议少使用

  • 作者:一个萝卜一个坑哦
  • 原文链接:https://blog.csdn.net/qq_27661691/article/details/103214181
    更新时间:2022-09-09 11:16:45