title: Is it good practice to try-with-resource a file writer
body: <p>I saw this example on the web and in the Book &quot;Effective Java&quot; (by Joshua Bloch).</p>
  <pre><code>try(BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))){
    writer.write(str); // do something with the file we've opened
  }
  catch(IOException e){
    // handle the exception
  }
  </code></pre>
  <p>There is no problem with this example, <code>BufferedWriter</code> which will automatically get closed and that, in turn, will close the <code>FileWriter</code>; however, in other case, if we declare 2 nested resources this way:</p>
  <pre><code>try (AutoClosable res = new Impl2(new Impl1())) {... }
  </code></pre>
  <p>I guess it might happen that <code>new Impl1()</code> performs fine, but <code>new Impl2()</code> crashes, and in this case Java would have no reference to the <code>Impl1</code>, in order to close it.</p>
  <p>Shouldn't it be a better practice to always declare multiple resources independently (even if not required in this case), like this?</p>
  <pre><code>try(FileWriter fw = new FileWriter(fileName); 
      BufferedWriter writer = new BufferedWriter(fw)){ ... }
  </code></pre>