davidl wrote:
在 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.
I agree. They keep on missing the point that the blessed code on the
normal path MUST NOT TAKE THE HIT OF AN EXTRA INDENTATION LEVEL. I am
screaming because people keep on falling in that trap in various
languages, mostly by copying without thinking from other languages. The
first language I know that did that mistake was Lisp itself.
Andrei