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?
Because enums were introduced in Java 5, and those libraries have been written long before. Refactoring them would break a bazillion of existing applications.
I find I still telling people to use enum for a Singleton even though it has been around for 7 years now. :P
When would use use constants instead of enum? When you have many associated but not directly related constants.
public static final int BUFFER_SIZE = 32 * 1024;
public static final String ERROR = "Error: ";
public static final char TAB = 't';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With