IntelliJ IDEA使用技巧--Live Templates 及Postfix

  • 常用Live Templates

模板

說明

sout
System.out.println($END$);
soutv
System.out.println("$EXPR_COPY$ = " + $EXPR$);

main

psvm

public static void main(String[] args){
  $END$
}

說明: 對於普通模板輸入後,回車/tab鍵即可;對於環繞的模板,選中代碼,再使用快捷鍵: ctrl+Alt+J,再選擇對應的模板.

位置:

  1. 快捷鍵:Ctrl + Shift + A,打開搜索框;輸入“live templates”
  2. 模板界面,可以查看預定義模板及進行自定義模板
  3. 預定義模板
  4. 自定義模板,根據各自需要進行定義使用.

  • 常用Postfix

postfix 說明
var Introduces variable for expression.定義變量

try

Insert statement in try-catch block.
soutv Creates System.out.println with a description of printed value call.
sout Creates System.out.println call.
return Returns value from containing method.

for

iter

Iterates over enumerable collection.
fori Iterates with index over collection.
if Checks boolean expression to be 'true'.
lambda Surrounds expression with lambda.
opt Creates Optional object.
while Iterating while boolean statement is 'true'.
switch Produces switch over integral/enum/string values.
synchronized Produces synchronization statement.

 

說明: 對應的方法/參數後.postfix回車,即可.如: m().try --->

try {
    m();
  } catch(CheckedException e) {
    e.printStackTrace();
  }

位置:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章