「Java」列挙型(Enum)によりコード値を取得するサンプル
1.列挙型(enum)の定義
package com.arkgame.study.it; public enum UserLevel { FLAG_A(12), FLAG_B(13), FLAG_C(14); // value definition private int value; // set value private UserLevel(int value) { this.value = value; } // return value public int value() { return this.value; } }
2.列挙UserLevelを使って、コード値を取得
package com.arkgame.study.it; public class SampleEnumDemo { public static void main(String[] args) { int n = 12; int m = 14; //enum java if (n == UserLevel.FLAG_A.value()) { System.out.println("develop department "); } if (m == UserLevel.FLAG_C.value()) { System.out.println("design department "); } } }
3.実行結果
develop department
design department