How can I gen an actual value from this enum with switch statement?
public enum Gender {
Unknown(0),
Male(1),
Female(2);
private static final SparseArray<Gender> lookupTable = new SparseArray<Gender>();
static {
for (final Gender gender : EnumSet.allOf(Gender.class)) {
lookupTable.put(gender.intValue, gender);
}
}
private final int intValue;
public static Gender getByIntValue(int val) {
return lookupTable.get(val);
}
private Gender(int intValue) {
this.intValue = intValue;
}
public int getIntValue() {
return intValue;
}
}
It is not entirely clear hat you mean with ‘actual value from this enum with switch statement‘. So here are the things to do with this enum:
You can use the enum in a
switch-statement as follows:If you want to grab
intValueof g, you can use:If you want to grab a
Gendervalue from anintyou can use:If you want to grab a
Gendervalue from aStringyou can use: