fork download
  1. class Ideone {
  2. public static void main(String[] args) {
  3. boo(Bar.bar1);
  4. // foo(new Baz()); // should not work - does not work
  5. // foo(Bang.bang1); // should not work - does not work
  6. }
  7.  
  8. public static <T extends Enum<T> & Foo<Integer>> void boo(T t) {
  9. System.out.println(t.ordinal());
  10. System.out.println(t.foo());
  11. }
  12. }
  13.  
  14. interface Foo<T> {
  15. T foo();
  16. }
  17.  
  18. enum Bar implements Foo<Integer> {
  19. bar1(1);
  20.  
  21. final int foo;
  22.  
  23. Bar(int foo) {
  24. this.foo = foo;
  25. }
  26.  
  27. @Override
  28. public Integer foo() {
  29. return foo;
  30. }
  31. }
  32.  
  33. class Baz implements Foo<Integer> {
  34. @Override
  35. public Integer foo() {
  36. return 42;
  37. }
  38. }
  39.  
  40. enum Bang {
  41. bang1
  42. }
Success #stdin #stdout 0.09s 47040KB
stdin
Standard input is empty
stdout
0
1