I'm new to Java and I can't seem to find the answer for this question even though it seems so simple.
I come from a C background and use to creating enums and using them by just calling the name of the enum like so...
enum Security_Levels
{
black_ops,
top_secret,
secret,
non_secret
};
So I could use black_ops and I would get a 0.
In Java you can define an enum in a separate folder and import it to where you want to use it. But unlike C I can't make a simple call to the enum objects.
public enum GroupID
{
camera,
projector,
preview,
slr,
led
}
When I try to call preview it doesn't work... I have to create an instance of the enum object
GroupID egroupid_preview = GroupID.preview;
Then even if I made an instance, I have to create Public functions to access the value as so below.
public enum GroupID
{
camera(1),
projector(2),
preview(3),
slr(4),
led(5);
private int val;
private GroupID(int val) {
this.val = val;
}
int getVal() {
return val;
}
}
Am I doing this all wrong or is there a reason java makes it so hard to access an enum?