fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.function.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. static Foo foo;
  12.  
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. System.out.println(testInt());
  16. System.out.println(testStr());
  17. }
  18.  
  19. static int testInt() {
  20. return get(() -> foo.getInt(), "");
  21. }
  22.  
  23. static String testStr() {
  24. return get(() -> foo.getInt(), "");
  25. }
  26.  
  27. static class Foo {
  28. int getInt() {
  29. return 1;
  30. }
  31. }
  32.  
  33. static <T> T get(Supplier<T> supplier, T defaultValue) {
  34. try {
  35. return supplier.get();
  36. } catch (NullPointerException e) {
  37. return defaultValue;
  38. }
  39. }
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:20: error: incompatible types: inferred type does not conform to upper bound(s)
		return get(() -> foo.getInt(), "");
		          ^
    inferred: INT#1
    upper bound(s): Integer,Object
  where INT#1,INT#2 are intersection types:
    INT#1 extends Object,Serializable,Comparable<? extends INT#2>,Constable,ConstantDesc
    INT#2 extends Object,Serializable,Comparable<?>,Constable,ConstantDesc
Main.java:24: error: incompatible types: inferred type does not conform to upper bound(s)
		return get(() -> foo.getInt(), "");
		          ^
    inferred: INT#1
    upper bound(s): String,Object
  where INT#1,INT#2 are intersection types:
    INT#1 extends Object,Serializable,Comparable<? extends INT#2>,Constable,ConstantDesc
    INT#2 extends Object,Serializable,Comparable<?>,Constable,ConstantDesc
2 errors
stdout
Standard output is empty