Feedback and comments on ARM proposal - resend

Howard Lovatt howard.lovatt at iee.org
Sat Mar 14 19:55:01 PDT 2009


Neal Gafter said:

> The destructor model does not require allocating objects on the stack.
> A language change along these lines analogous to this ARM proposal
> would provide a new modifier on a local variable, and treat the code
> from the declaration point to the point where the variable goes out of
> scope much the same way as the ARM proposal treats the try block.

Instead of writing:

try ( Resource r = new Resource() ) {
  r.doSomething();
}

You would write:

final Resource r = new Resource();
r.doSomething();

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?

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.



More information about the coin-dev mailing list