Home:ALL Converter>Why use constants instead of enums?

Why use constants instead of enums?

Ask Time:2011-08-08T15:18:11         Author:Michael Studebaker

Json Formatter

I've seen in lots and lots of Java libraries the use of lots of constants where enums could have easily been used. Even in Swing, there is a lot of code that uses constants instead of enums. Why?

What are the disadvantages to using enums?

Author:Michael Studebaker,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/6978878/why-use-constants-instead-of-enums
sudmong :

Enums in java are introduced in Java 5, these were not there before and Enum is equivalent to a class in java.",
2011-08-08T07:21:19
JB Nizet :

Because enums were introduced in Java 5, and those libraries have been written long before. Refactoring them would break a bazillion of existing applications.",
2011-08-08T07:20:30
Peter Lawrey :

\nThere is a lot of documentation of using pre-enum solutions. \nThere are lots of developers who are using Java for the first time and have experience with another language where using constants is the norm.\nA lot of libraries wanted to support Java 1.4 and earlier. Java 1.3 & 1.4 are still used today.\nWorking code hasn't been re-written just to use enums.\n\n\nI find I still telling people to use enum for a Singleton even though it has been around for 7 years now. :P\n\nWhen would use use constants instead of enum? When you have many associated but not directly related constants.\n\npublic static final int BUFFER_SIZE = 32 * 1024;\npublic static final String ERROR = \"Error: \";\npublic static final char TAB = 't';\n",
2011-08-08T07:23:36
yy