
Untitled
By: a guest on
Aug 7th, 2012 | syntax:
None | size: 0.59 KB | hits: 8 | expires: Never
The right and wrong approach to writing Java Enums
public interface Base<T> {
public T fromValue(String v);
}
public enum AddressType implements Base<AddressType> {
NotSpecified("Not Specified."),
Physical("Physical"),
Postal("Postal");
private final String label;
private AddressType(String label) {
this.label = label;
}
public String getLabel() {
return this.label;
}
@Override
public AddressType fromValue(String v) {
return valueOf(v);
}
}
AddressType type = AddressType.Postal.valueFrom("Physical");