0
can enum values be assigned to integer values for calculations?
enum Month {Jan=1,Feb=2,Mar=3,Apr=4,May=5} Is anything like this possible instead of just,, enum Month {Jan,Feb,Mar,Apr,May} I mean, if(Month==1) would be more preferable than if(Month==Jan)
1 ответ
+ 1
In Java enums are similar to classes, so you can do the following:
public enum Something {
OPEN(100), CLOSE(200);
private final int id;
Something(int id) { this.id = id; }
public int getValue() { return id; }
}
See this link for more info: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html