When i try to give a value to my enum, it gives me this error:
constructor status in enum status cannot be applied to given types; STATUS_OPEN(0),
why is this happening and how do i fix it?
here is my code thus far:
public enum Status
{
STATUS_OPEN(0),
STATUS_STARTED(1),
STATUS_INPROGRESS(2),
STATUS_ONHOLD(3),
STATUS_COMPLETED(4),
STATUS_CLOSED(5);
}
i'm using notepad and the jdk via command prompt - i don't want to use netbeans or eclipse at the moment. Also, i've never used an enum before or java! So please bare with me..
Oh yes, and i was following this site: link
I've googled around and I couldn't really find why this issue is occuring or how to fix it by searching for the error...
解决方案
You need to add a constructor to the enum.
public enum Status {
STATUS_OPEN(0),
STATUS_STARTED(1),
STATUS_INPROGRESS(2),
STATUS_ONHOLD(3),
STATUS_COMPLETED(4),
STATUS_CLOSED(5);
private final int number;
Status(int number) {
this.number = number;
}
public int getMagicNumber() { return number; }
}
This'll fix your syntax problems, but what are you hoping to achieve with the number? Enums are often used instead of the need for numbers at all.