gpt4 book ai didi

java - 在 IntelliJ IDEA 中,如何使用 try-with-resources 包围?

转载 作者:搜寻专家 更新时间:2023-10-30 21:05:10 26 4
gpt4 key购买 nike

在 IntelliJ IDEA 中,我可以按“Surround with”快捷键 CTRL-ALT-T 用 try/catch block 包围一个代码块,等等东西。

我想将资源部分包围在一个 try-with-resources block 中:

Writer out = Files.newBufferedWriter(destination, StandardCharsets.UTF_8);
temp.process(model, out);

对此:

try (Writer out = Files.newBufferedWriter(destination, StandardCharsets.UTF_8)) {
temp.process(model, out);
}

但是,当按下 CTRL-ALT-T 时,此选项不可用。

如何用 try-with-resources block 包围一段代码?

最佳答案

在代表 AutoCloseable 的任何表达式上按 ALT-ENTER

用 try-with-resources block 环绕”是一个意图 Action 。它不是“环绕声”菜单中可用的选项。

try with resources screenshot

关于java - 在 IntelliJ IDEA 中,如何使用 try-with-resources 包围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39862408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com