fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3.  
  4.  
  5. import java.util.function.Supplier;
  6. import java.util.stream.Collectors;
  7. import java.util.stream.Stream;
  8.  
  9. class Tmp {
  10. static <T> T readValue(Supplier<T> s, Class<T> type) throws Exception {
  11. return s.get();
  12. }
  13. interface Source extends Supplier<String>, AutoCloseable {
  14. public default void close() throws Exception {}
  15. }
  16.  
  17. public static void main(String[] args) {
  18. Stream.of("one", "two", "three")
  19. .map(s -> {
  20. try(Source source = () -> s) {
  21. return readValue(source, String.class);
  22. }
  23. catch(Exception ex) {
  24. return null;
  25. }
  26. })
  27. .forEach(System.out::println);
  28. }
  29. }
  30.  
Success #stdin #stdout 0.14s 4386816KB
stdin
Standard input is empty
stdout
one
two
three