Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6336

[PARROT] Support Java 7 ARM blocks

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.0-beta-2
    • 3.0.0-alpha-1, 2.6.0-alpha-1
    • Compiler
    • 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

          Activity

            People

              daniel_sun Daniel Sun
              tomd Tom Dunstan
              Votes:
              4 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: