Consider the following code
public class ColorScheme {
public static final int DARK_BLACK = 0,
WHITE = 1;
private int Scheme;
public ColorScheme() {
this.Scheme = DARK_BLACK;
}
public ColorScheme(int SchemeType) {
this.Scheme = SchemeType;
}
}
I want the argument to the constructor ColorScheme(int SchemeType) to be restricted to one of the static final int – DARK_BLACK or WHITE or other constant I may define.
For Ex: When someone instantiates the ColorScheme class, he can use
ColorScheme CS = new ColorScheme(DARK_BLACK);
while
ColorScheme CS = new ColorScheme(5); //or any other non-defined constant
should return an error.
Enum is the way to go: