Feature Overview
This feature generates a full-fledged enum class.
This feature generates a full-fledged enum class.
None
public enum EnumDemo {
One('1'),
Two('2'),
Three('3');
private String id;
private EnumDemo(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
}public class EnumDemo extends Sweet.BaseEnum {
public static final EnumDemo One = (EnumDemo)new EnumDemo('1').setName('One').setOrdinal(0);
public static final EnumDemo Two = (EnumDemo)new EnumDemo('2').setName('Two').setOrdinal(1);
public static final EnumDemo Three = (EnumDemo)new EnumDemo('3').setName('Three').setOrdinal(2);
private static final Map instances = new Map{ 'One' => One, 'Two' => Two, 'Three' => Three };
public static List values() {
return instances.values();
}
public static EnumDemo valueOf(String name) {
return instances.get(name);
}
private String id;
private EnumDemo(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
} Generated enums are all subclasses of Sweet.BaseEnum, and they share the same API.
| Method Name | Description |
|---|---|
| toString() | Get the name of the enum |
| ordinal() | Get the ordinal of the enum |
| static BaseEnum valueOf(String) | Get the enum by name |
| static List | Get all enum values |
Contribute on Github! Edit this section.