Enum Alternative Java Example

Enum Alternative Java Example

In Java Enum type has been introduced, which is a special data type it enables for variable to be a set of predefined constants. The variable should be equal to one of the values that have been predefined for it. But here we are will create Enum but will discuss about alternative of Enum. This was required to me when I was working with Oracle Coherence which does not support Enum types so I had to take an alternative approach to define my constant.

  • Let’s say you have Enum called ExpirySettlementType.java and you need to take alternative of this:

  • Enum alternative EnumAlternativeConstant.java:

As you see above I have created Enum alternative constant class. Now Let’s create test class to pass and retrieve its value:

  • EnumAlternativeTest.java:

Above example is Enum with two variable constant and If you are looking for Enum with single constant variable please see example below: 

  • Enum¬†AnchorType.java;

  • Enum alternative¬†AnchorTypeConstant.java:

  • OR you could use below if you don’t want to use constructor:


Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *