Feedback and comments on ARM proposal (original) (raw)
Neal Gafter neal at gafter.com
Sat Mar 14 21:04:48 PDT 2009
- Previous message: Feedback and comments on ARM proposal - resend
- Next message: Feedback and comments on ARM proposal - resend
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Mar 14, 2009 at 7:55 PM, Howard Lovatt <howard.lovatt at iee.org> wrote:
Instead of writing:
try ( Resource r = new Resource() ) { r.doSomething(); } You would write: final Resource r = new Resource(); r.doSomething();
I think this requires something like a new modifier on the local variable declaration. Without a distinguished syntax, I don't see how to distinguish this from a normal local variable declaration.
This is so much more Java like than the block construct, why not do this instead of the block construct (note it would be an error not to declare the resource final). r.dispose() is called at the end of the enclosing block, provided that r is not null, when r goes out of scope, which is probably what you want anyway (you can insert an existing {} block if you have to control lifetime). Also, why not make the dispose method exception free, realistically what can a user of an API do if dispose throws an exception?
If it's not final, what happens when the variable is reassigned?
Without allowing checked exceptions on the resource release, I don't see how to retrofit this onto the primary use-case, Closeable.
Neal also suggested that for each loops should understand Disposable, this is a good suggestion as looping is common with rources and it also fits well with his other suggestion above.
- Previous message: Feedback and comments on ARM proposal - resend
- Next message: Feedback and comments on ARM proposal - resend
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]