Using java keyword when declaring an enumeration

Once, I had this particular case where I needed to have an enumeration with the double java keyword. I also wanted that a call on this enumeration would return me the “double” String.

If you try to type this :

You will get an error from the compiler saying that you cannot use the double keyword.

Here an elegant solution to achieve this :

This is possible due to the fact the enum is a class. We can then manipulate the name attribute

Leave a Reply

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