简体   繁体   中英

Why are not some of the constant fields in java enum values?

The documentation about the ScrollPane uses no enum values for the scrollbar policy (and neither does any other class for constant field values), is there a reason for that?

Is there a more in depth meaning of the values for these constant field values or are they just in ascending order? Because in my opinion having a constructor like public ScrollPane(int scrollbarDisplayPolicy) looks not as meaningful as for example public ScrollPane(ScrollPane.ScrollbarDisplayPolicy scrollbarDisplayPolicy)

Or is this just to have not multiple enums with only a few values?

The answer is simple: enum s were only introduced in Java 5 and these constants are older than that.

Unfortunately there is no way to retro-fit the API without breaking code compatibility. (Retro-fitting an API for new features sounds an impossible task in general, but an example of when this was possible is the introduction of generics, also in Java 5.)

Java enum was introduced in version 1.5.

So most of the libraries which was developed before java 1.5 uses, static final constants.

For example, log4j levels are also public static final values of integer value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM