How can you get the underlying/derived Type(byte, short, int, etc) of an enum?
As we have learned, we cannot inherit enum classes in Java. However, enum classes can implement interfaces.
Nope. it is not possible. Enum can not inherit in derived class because by default Enum is sealed.
There is no inheritance with enums. You can instead use classes with named const ints.
You are looking for Enum.GetUnderlyingType(enumType)
;
Sample from MSDN:
static object GetAsUnderlyingType(Enum enval)
{
Type entype = enval.GetType();
Type undertype = Enum.GetUnderlyingType(entype);
return Convert.ChangeType(enval, undertype);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With