fork download
  1. enum Thing implements HasCaste {
  2. Type1 {
  3. @Override
  4. public Class<String> getCaste() {
  5. return String.class;
  6. }
  7. }, Type2 {
  8. @Override
  9. public Class<Integer> getCaste() {
  10. return Integer.class;
  11. }
  12. };
  13.  
  14. public static void main(String[] args) {
  15. Class<String> c = Type1.getCaste();
  16. }
  17. }
  18.  
  19. interface HasCaste {
  20. public Class<?> getCaste();
  21. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:15: error: incompatible types: Class<CAP#1> cannot be converted to Class<String>
        Class<String> c = Type1.getCaste();
                                        ^
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ?
1 error
stdout
Standard output is empty