Java – why use constants instead of enumerations?

I have seen the use of many constants in many Java libraries, in which enumerations can be easily used Even in swing, a lot of code uses constants instead of enumerations Why?

What are the disadvantages of using enumeration?

Solution

>There are many documents that use the pre enum solution

I find that I still tell people to use enum as singleton, even though it has existed for 7 years: P

When do I use constants instead of enumerations? When you have many related 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';
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>