public enum Status { Open("O"), Closed("C"), Reopened("R") final String code; Status(String code) { this.code = code; } };
you can use the attribute as you would for any other class, eg:
Status[] values = Status.values(); for(Status statue : values) { System.out.println(status.code + " - " + status); }
result:
O - Open
C - Closed
R - Reopened
1.enum String:
Open("O"), Closed("C"), Reopened("R")
2.enum range:
Low(0,100), Medium(101,1000), High(1000, 10000);
3. enum boolean:
Open(true), Closed(false), Reopened(true);
reference :http://java.dzone.com/blogs/mrjohnsmart/2008/05/19/a-short-primer-java-enums-part
0 comments:
Post a Comment