在 Mon, 02 Mar 2009 08:02:35 +0800,bearophile <[email protected]> 写道:

From:
http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-jdk7.html

Automated Resource Blocks, to be able to say things like:

try (BufferedReader br = new BufferedReader(new FileReader(path)) {
  return br.readLine();
}

instead of:

BufferedReader br = new BufferedReader(new FileReader(path));
try {
   return br.readLine();
} finally {
   br.close();
}

based on having BufferedReader implement a Disposable interface.

------------------

Exception handling improvements:

try {
    doWork(file);
} catch (final IOException | SQLException ex) {
    logger.log(ex);
    throw ex;
}

Bye,
bearophile

I believe it is worse than scope(exit) resource.dispose(); in terms of syntax.

Reply via email to