2

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?

2 Answers 2

3

The answer is simple: enums 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.)

Sign up to request clarification or add additional context in comments.

2 Comments

Do you know if they use enums for classes they have added after enums were introduced or do they still stick to the old way?
@Marcono1234 No, they stick to the old way as far as I can tell, for example here. But in entirely new APIs, like JavaFX, enums are very much the norm.
2

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.

1 Comment

And java.util.logging, introduced in 1.4, uses the pre-Java 5 typesafe enum class idiom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.