好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Java中对于双属性枚举的使用案例

最近有小伙伴问我,双枚举类该怎么写,还得包括根据 key 取值方法。

于是就手写一个案例如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

/**

  * 关系类型枚举

  */

public enum relationtype {

  mapping( 0 , "映射" ),

  quote( 1 , "引用/授权" ),

  entrust( 2 , "委托" ),

  agent( 3 , "代理" );

  private int value;

  private string desc;

  relationtype( int value ,string desc) {

  this .value = value;

  this .desc = desc;

  }

  public int getvalue() {

     return value;

   }

  public string getdesc() {

  return desc;

  }

  public static string getdescbyvalue( int value) {

  for (relationtype enums : relationtype.values()) {

   if (enums.getvalue() == value) {

   return enums.getdesc();

   }

  }

  return "" ;

  }

}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接

原文链接:https://blog.csdn.net/moneyshi/article/details/80083360

查看更多关于Java中对于双属性枚举的使用案例的详细内容...

  阅读:14次