try-with-resources
Per Bothner
per@bothner.com
Sat Jan 7 21:13:00 GMT 2012
On 01/07/2012 01:12 AM, Helmut Eller wrote:
> Just wondering, does Kawa already have somehing like the extened try in
> Java7?
Not yet - though it seems a reasonable thing to add.
A possible syntax:
(try-with-resources
((VAR [:TYPE] INIT) ...)
BODY)
(The Java "extended" try-with-resources with a catch-clause
or a finally-clause is just a basic try-with-resources
inside of a traditional try statement, so no need to support
that in the Kawa try-with-resources syntax, IMO.)
I haven't looked at the specification closely enough to see if
it can be implemented using a macro only.
I don't know if there is any SRFI or other Scheme that has
something similar, in which case we should consider that as well.
> And would that work on Java6 too?
try-with-resources is defined in terms of java.lang.AutoCloseable,
which is specific to Java7. It would be plausible for Java6 to
implement a restricted version that uses java.io.Closeable.
Or one could just accept any class with a close method - I don't
know if that would cause problems.
try-with-resources also assumes Throwable#addSuppressed, which
is new in java7, though a java6 "backport" could skip that.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list