【问题标题】:eclipse try-with-resource template?eclipse try-with-resource 模板?
【发布时间】:2014-05-16 15:01:21
【问题描述】:

Eclipse 支持 try-with-resource,有点像这样:

try(Outputstream resource = new FileOutputStream(file)){
// do something...
}

这个功能添加到 Eclipse 已经有好几年了,但是没有模板“try-with-reousource”。只有一个是“try-catch”。

我尝试制作模板,例如try($type{} ${localVar} = new $type{}){ {$cursor{} },但没用。 (也建议使用非 AutoClosable 类型)

有什么有用的try-with-resource模板吗?

【问题讨论】:

    标签: java eclipse templates try-with-resources


    【解决方案1】:

    Eclipse 中不包含“try-with-resource”模板。

    有一个未解决的问题:Bug 351864 - [1.7][templates] Add 'try-with-resource' template

    【讨论】:

      【解决方案2】:

      Eclipse 4.22(2021 年第四季度,7 年后)可能会提供该功能:

      Surround with try-with-resources quickfix

      已创建一个新的快速修复程序,以便在相关资源实现 AutoCloseable 时为带有 try-with-resources 的 Surround 提供资源泄漏和潜在资源泄漏。

      快速修复示例:

      【讨论】:

        猜你喜欢
        • 2016-03-12
        • 2017-02-13
        • 1970-01-01
        • 1970-01-01
        • 2016-09-25
        • 1970-01-01
        • 1970-01-01
        • 2015-11-26
        • 2014-01-06
        相关资源
        最近更新 更多