Usage of a Custom Ordinal in Enum

Usage of a Custom Ordinal in Enum

The getCustomValue() method on the enum returns the custom value associated. You can use this mechanism when you want to override the default ordinal with a custom ordinal.

Code snippet

public class CustomEnumOrdinal{   public static void main(String args[])   {      CustomEnumOrdinal customEnumOrdinal = new CustomEnumOrdinal();      customEnumOrdinal.proceed();   }      enum Days {      SUNDAY(1), MONDAY(2), TUESDAY(3), WEDNESDAY(4), THURSDAY(5), FRIDAY(6), SATURDAY(7);            int customValue;      Days(int customValueArg)      {         customValue = customValueArg;      }            int getCustomValue()      {         return customValue;      }   }      private void proceed()   {      Days ordinalDay = Days.FRIDAY; //Change this value to one of the values in the enum Days to get the respective custome ordinal value      System.out.println("Custom ordinal of " + ordinalDay + " is " + ordinalDay.getCustomValue());   }}/*Expected output: Custom ordinal of FRIDAY is 6*/
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular