fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public interface Interface
  11. {
  12. default String getValue()
  13. {
  14. return this.toString() + ":"+this.getClass().getSimpleName();
  15. }
  16. }
  17.  
  18. public enum Enum1 implements Interface
  19. {
  20. A, B, C, D;
  21. }
  22. public enum Enum2 implements Interface
  23. {
  24. A, B, C, D, E, F;
  25. }
  26.  
  27. public static <T extends Enum<T> & Interface> void test(T t)
  28. {
  29. System.out.println(t.getValue());
  30. }
  31.  
  32. public static void main(String[] args)
  33. {
  34. test(Enum1.A);
  35. test(Enum1.C);
  36. test(Enum2.B);
  37. test(Enum2.E);
  38. }
  39. }
Success #stdin #stdout 0.11s 320512KB
stdin
Standard input is empty
stdout
A:Enum1
C:Enum1
B:Enum2
E:Enum2