我是 Groovy 的新手。在处理 I/O 流期间,我曾经在 Java 代码中使用“try-with-resources”构造。
您能否建议一下,Groovy 中是否有类似的构造?
最佳答案
Groovy 2.3 还有 withCloseable
它将适用于任何实现 Closeable 的东西
Groovy 3 新闻快讯
Groovy 3+ 像 Java 一样支持 try..with..resources
https://groovy-lang.org/releasenotes/groovy-3.0.html#_arm_try_with_resources
关于Groovy, "try-with-resources"构造替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23382079/