Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.2.0-beta-2
-
None
Description
Currently Groovy does not have an equivalent to Java 7's ARM blocks. The closest is adding a method which takes a closure to the class that you'd like to be auto-closed (or whatever gives you that resource), and implementing the closing logic in that method. This has a host of problems:
- It's inefficient, requiring multiple method calls and an extra closure class over the Java solution
- Since the closure-accepting methods are added ad-hoc, they have different names and quite possibly subtly different behaviour, particularly around what happens if an exception is thrown during the closing. By contrast this is well defined in Java 7 so a programmer doesn't have to go hunting for documentation or source code on the method that they're calling
- If you are trying to work with an existing Java library rather than Groovy code, you're out of luck, since short of metaclass hacking you won't be able to add a wrapper method anyway
It would also be nice to keep Groovy and Java syntax as consistent as possible to ease porting between the two.
Attachments
Issue Links
- Dependency
-
GROOVY-8586 [PARROT] Support Java 9 ARM blocks
- Closed