fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.concurrent.Callable;
  5. import java.util.function.Supplier;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static Map<String, Number> createMap() {
  11. return new HashMap<>();
  12. }
  13.  
  14. public static <T> T get(final Callable<T> _valueCreator, final Supplier<T> _errorValue) {
  15. try {
  16. return _valueCreator.call();
  17. } catch (final Exception e) {
  18. return _errorValue.get();
  19. }
  20. }
  21.  
  22. public static Map<String, Number> getCachedMap() {
  23. return get(Ideone::createMap, Collections::emptyMap);
  24. }
  25.  
  26. public static void main(String[] args) {
  27. System.out.println(getCachedMap());
  28. }
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:23: error: incompatible types: inferred type does not conform to upper bound(s)
        return get(Ideone::createMap, Collections::emptyMap);
                  ^
    inferred: Map<? extends Object,? extends Object>
    upper bound(s): Map<String,Number>,Object
1 error
stdout
Standard output is empty