Small Changes for Java JDK7
davidl
davidl at 126.com
Mon Mar 2 05:28:08 PST 2009
在 Mon, 02 Mar 2009 08:02:35 +0800,bearophile <bearophileHUGS at lycos.com>
写道:
> 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.
More information about the Digitalmars-d
mailing list