Skip to content

Instantly share code, notes, and snippets.

@takaki
Created October 17, 2017 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaki/8f86ee83473a86d4e5a61f2dbc95dba6 to your computer and use it in GitHub Desktop.
Save takaki/8f86ee83473a86d4e5a61f2dbc95dba6 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
public enum SampleEnum {
AAA(1),
BBB(2),
CCC(3);
public static final int SIZE = java.lang.Integer.SIZE;
private int intValue;
private static HashMap<Integer, SampleEnum> mappings = new HashMap<>();
private static HashMap<Integer, SampleEnum> getMappings() {
return mappings;
}
SampleEnum(int value) {
intValue = value;
getMappings().put(value, this);
}
public int getValue() {
return intValue;
}
public static SampleEnum forValue(int value) {
return getMappings().get(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment