Guest User

Untitled

a guest
May 19th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1.     static AutoCloseable of(List<? extends AutoCloseable> l) {
  2.         return () ->
  3.             l.forEach(ac -> {
  4.                 try {
  5.                     ac.close();
  6.                 } catch (Exception e) {
  7.                     // ...
  8.                 }
  9.             });
  10.     }
  11.  
  12.     public static void main(String[] args) throws Exception {
  13.         List<ByteArrayOutputStream> oss = new ArrayList<>();
  14.         try (AutoCloseable toBeAutoClosed = of(oss)) {
  15.             System.out.println("Hello");
  16.         }
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment