How to cast a value from one enum to another in Java? -
How do I add Enum1 to Enum 2 value in Java? Here's an example of what I'm trying to do:
Public Enumum Enum1 {ONE, TWO, THREE; } Public Enum Enum2 {Four, Five, Six; } So I want to do something like this:
Enum2 en2 = (Enum2) A; Is this possible and how can I do this?
Thanks in advance!
You can not put one value from one in the other, although each enum is a guaranteed order, and you can easily One can translate from enum to another (order of protection). For example:
enum E1 {ONE, TWO, THREE,} enum E2 {ALPHA, BETA, GAMMA}} We can translate E1.TWO to / from E2.BETA By: Fixed E2 E1toE2 (E1 value) {return E2.values () [Value.ordinal ()]; } Fixed E1 E2toE1 (E2 value) {return E1.values () [value.ordinal ()]; }
Comments
Post a Comment