I noticed that this won't compile:
PrintWriter printWriter = new PrintWriter("test.txt"); printWriter.append('a'); printWriter.close(); printWriter = null; try(printWriter = new PrintWriter("test.txt")) { } with: Error:(17, 24) java: <identifier> expected
Only a new variable works at this point:
try(PrintWriter printWriter2 = new PrintWriter("test.txt")) { } My intuition is that only a new object should be required, but apparently a new reference is needed. Clearly this is a result of compile-time type checking, but why doesn't the old reference work?