Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.56 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to implement enum with generics?
  2. interface A<T> {
  3.     T getValue();
  4. }
  5.        
  6. public enum B implements A {
  7.     A1<String> {
  8.         @Override
  9.         public String getValue() {
  10.             return "value";
  11.         }
  12.     },
  13.     A2<Integer> {
  14.         @Override
  15.         public Integer getValue() {
  16.             return 0;
  17.         }
  18.     };
  19. }
  20.        
  21. public Enum B implements A<String> {
  22.   A1, A2;
  23. }
  24.        
  25. public class B<T> implements A<T> {
  26.     public static final B<String> A1 = new B<String>();
  27.     public static final B<Integer> A2 = new B<Integer>();
  28.     private B() {};
  29. }