Guest User

Untitled

a guest
Aug 7th, 2012
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. The right and wrong approach to writing Java Enums
  2. public interface Base<T> {
  3.  
  4. public T fromValue(String v);
  5.  
  6. }
  7.  
  8. public enum AddressType implements Base<AddressType> {
  9.  
  10. NotSpecified("Not Specified."),
  11.  
  12. Physical("Physical"),
  13.  
  14. Postal("Postal");
  15.  
  16. private final String label;
  17.  
  18. private AddressType(String label) {
  19. this.label = label;
  20. }
  21.  
  22. public String getLabel() {
  23. return this.label;
  24. }
  25.  
  26. @Override
  27. public AddressType fromValue(String v) {
  28. return valueOf(v);
  29. }
  30. }
  31.  
  32. AddressType type = AddressType.Postal.valueFrom("Physical");
Advertisement
Add Comment
Please, Sign In to add comment