The simplest attempt to use resources for all versions of Groovy is as follows (it even works with the AutoCloseable interface). Where the Thing class is a AutoCloseable class or implements AutoCloseable .
new Thing().with { res -> try { // do stuff with res here } finally { res.close() } }
Which is equivalent in later versions of Groovy:
new Thing().withCloseable { res -> // do stuff with res here }
Sam Gleske Apr 12 '19 at 4:41 2019-04-12 04:41
source share