I am not sure if this is a definitive statement, but it seems to me that the Java API prefers constant ints over enums. From the parts of the API that I have used, I've encountered many final static int
constants where an enum
could have been used instead. Once such example that I happen to be staring at this moment:
From java.awt.BasicStroke:
public final static int CAP_BUTT = 0;
public final static int CAP_ROUND = 1;
public final static int CAP_SQUARE = 2;
In fact, I don't think I've ever seen an enum used in a standard Java API class. Why is this?
I'm designing an API for my own application (about a billion times smaller than the Java API, but I'm still trying to be smart about it), and trying to decide whether to use constant ints or enums. THIS post references a very popular book I haven't read yet which implies enums have many advantages. Most other highly scored answers in that same thread agree. So why does Java not seem to use its own enum capabilities?