Function level try recourse directives.

Red IO redio.development at gmail.com
Tue Dec 27 13:49:13 UTC 2022


I was once again writing closing heavy code in a java method and was
wondering if I could reduce the clutter of the multi line try block:
try (var foo1 = new Foo1() ;
var foo2 = new Foo2() ;
....) {
...
}
Sometimes we need to initialize something between the resources and we get
multiple levels of nesting.
And I was wondering if we could not just lose the block and auto close at
the end of a method like this :

void foo() {
try (var foo1 = new Foo1());
//init some stuff
try (var foo2 = new Foo2());
// do some stuff
// auto close at end of method
}

I think method level try recourse would improve readability and unnecessary
nesting significantly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221227/e1f271b3/attachment.htm>


More information about the amber-dev mailing list