Edit: My solution is pretty useless since as quew8 pointed out you can use a private constructor.
I was wondering how to group ints in a way which would allow me to create a type-safe argument for a constructor/method. At first I didn’t think this was possible without using a switch statement with an enum, so I just grouped them in nested classes, but today I was playing with enums (I never really use them much) and found that I could do this. E.g, if you want to group OpenGL data types you can do this.
public enum DataType {
BYTE {
@Override
int getType() {
return GL_BYTE;
}
},
SHORT {
@Override
int getType() {
return GL_SHORT;
}
} // etc...;
abstract int getType();
}
If you want to use it as an argument for a method, e.g uselessly returning the type from another method, you can do:
public int returnType(DataType type) {
return type.getType();
}
And to access it you’d pass in, e.g:
returnType(DataType.BYTE);
Hopefully this could save someone a days headache.