fork(7) download
  1. import java.util.*;
  2.  
  3. interface Foo { void foo(); }
  4. interface Bar { void bar(); }
  5.  
  6. class Humpty implements Foo, Bar {
  7. public void foo() { System.out.println("Humpty.foo()"); }
  8. public void bar() { System.out.println("Humpty.bar()"); }
  9. }
  10.  
  11. class Dumpty implements Foo, Bar {
  12. public void foo() { System.out.println("Dumpty.foo()"); }
  13. public void bar() { System.out.println("Dumpty.bar()"); }
  14. }
  15.  
  16. public class Main {
  17. @SuppressWarnings("unchecked")
  18. public static <FooBar extends Foo & Bar> void main(String[] args) {
  19. // I actually have no idea what the syntax should be.
  20. Random random = new Random();
  21. // Fix: I previously used <? extends Foo, Bar>, thanks Jon Skeet and vijucat
  22. FooBar foobar;
  23. if (random.nextBoolean())
  24. foobar = (FooBar) new Humpty();
  25. else
  26. foobar = (FooBar) new Dumpty();
  27. foobar.foo();
  28. foobar.bar();
  29. }
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
spoj: The program compiled successfully, but main class was not found.
      Main class should contain method: public static void main (String[] args).
stdout
Standard output is empty