2016-10-04 58 views
6

在IntelliJ IDEA中,我可以按下「Surround與」快捷方式CTRL-ALT-T以使用try/catch塊包圍代碼塊等等。在IntelliJ IDEA中,如何用try-with-resources包圍?

我想資源的一部分環繞成一試,與資源塊:

Writer out = 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塊來包圍代碼塊?

回答

5

ALT-ENTER代表AutoCloseable的任何表達式。

環繞帶嘗試資源塊」是意圖動作。 「Surround with」菜單中不提供此選項。

try with resources screenshot