一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - IDEA巧用Postfix Completion讓碼速起飛(小技巧)

IDEA巧用Postfix Completion讓碼速起飛(小技巧)

2020-08-26 00:17白菜Java自習室 Java教程

這篇文章主要介紹了IDEA巧用Postfix Completion讓碼速起飛,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1. 情景展示

自從做 Java 開發(fā)之后,IDEA 編輯器是不可少的。 在 IDEA 編輯器中,有很多高效的代碼補全功能,尤其是 Postfix Completion 功能,可以讓編寫代碼更加的流暢。

Postfix completion 本質(zhì)上也是代碼補全,它比 Live Templates 在使用上更加流暢一些,我們可以看一下下面的這張圖。

IDEA巧用Postfix Completion讓碼速起飛(小技巧)

2. 設(shè)置界面

可以通過如下的方法打開 Postfix 的設(shè)置界面,并開啟 Postfix。

IDEA巧用Postfix Completion讓碼速起飛(小技巧)

3. 常用的 Postfix 模板

3.1. boolean 變量模板

!: Negates boolean expression

?
1
2
3
4
5
6
7
8
9
10
11
12
13
//before
public class Foo {
   void m(boolean b) {
     m(b!);
   }
 }
 
//after
public class Foo {
  void m(boolean b) {
    m(!b);
  }
}

if: Checks boolean expression to be 'true'

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//before
public class Foo {
  void m(boolean b) {
    b.if
  }
}
 
//after
public class Foo {
  void m(boolean b) {
    if (b) {
 
    }
  }
}

else: Checks boolean expression to be 'false'.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//before
public class Foo {
  void m(boolean b) {
    b.else
  }
}
 
//after
public class Foo {
  void m(boolean b) {
    if (!b) {
 
    }
  }
}

3.2. array 變量模板

for: Iterates over enumerable collection.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//before
public class Foo {
  void m() {
    int[] values = {1, 2, 3};
    values.for
  }
}
 
//after
public class Foo {
  void m() {
    int[] values = {1, 2, 3};
    for (int value : values) {
 
    }
  }
}

fori: Iterates with index over collection.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//before
public class Foo {
  void m() {
    int foo = 100;
    foo.fori
  }
}
 
//after
public class Foo {
  void m() {
    int foo = 100;
    for (int i = 0; i < foo; i++) {
 
    }
  }
}

3.3. 基本類型模板

opt: Creates Optional object.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//before
public void m(int intValue, double doubleValue, long longValue, Object objValue) {
 intValue.opt
 doubleValue.opt
 longValue.opt
 objValue.opt
}
 
//after
public void m(int intValue, double doubleValue, long longValue, Object objValue) {
 OptionalInt.of(intValue)
 OptionalDouble.of(doubleValue)
 OptionalLong.of(longValue)
 Optional.ofNullable(objValue)
}

sout: Creates System.out.println call.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
//before
public class Foo {
 void m(boolean b) {
  b.sout
 }
}
 
//after
public class Foo {
 void m(boolean b) {
   System.out.println(b);
 }
}

3.4. Object 模板

nn: Checks expression to be not-null.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//before
public class Foo {
  void m(Object o) {
    o.nn
  }
}
//after
public class Foo {
  void m(Object o) {
    if (o != null){
 
    }
  }
}

null: Checks expression to be null.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//before
public class Foo {
  void m(Object o) {
    o.null
  }
}
//after
public class Foo {
  void m(Object o) {
    if (o != null){
 
    }
  }
}

notnull: Checks expression to be not-null.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//before
public class Foo {
  void m(Object o) {
    o.notnull
  }
}
//after
public class Foo {
  void m(Object o) {
    if (o != null){
 
    }
  }
}

val: Introduces variable for expression.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
//before
public class Foo {
  void m(Object o) {
    o instanceof String.var
  }
}
 
//after
public class Foo {
  void m(Object o) {
    boolean foo = o instanceof String;
  }
}

3.5. 其他模板

new: Inserts new call for the class.

?
1
2
3
4
5
//before
Foo.new
 
//after
new Foo()

return: Returns value from containing method.

?
1
2
3
4
5
6
7
8
9
10
11
12
//before
public class Foo {
  String m() {
    "result".return
  }
}
//after
public class Foo {
  String m() {
    return "result";
  }
}

到此這篇關(guān)于IDEA巧用Postfix Completion讓碼速起飛(小技巧)的文章就介紹到這了,更多相關(guān)IDEA Postfix Completion 內(nèi)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!

原文鏈接:https://juejin.im/post/6864742910290722829

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本 视频 在线 | 国产一区二区三区水野朝阳 | 四虎2021地址入口 | 欧美在线视频一区 | 国产成人在线综合 | 996热精品视频在线观看 | 高h全肉np触手 | 99视频精品免费99在线 | 91啪在线观看国产在线 | 青青草在视线频久久 | 色综合久久中文字幕 | 白丝女榨干蹂躏我 | 国产精品女主播大秀在线 | 99久久精品免费看国产高清 | 亚洲风情无码免费视频 | 青青草国产青春综合久久 | 日韩经典在线观看 | 亚洲精品二三区伊人久久 | 91手机在线 | 日本在线播放视频 | 男人影院天堂网址 | 国产一卡二卡四卡免费 | 国产午夜大片 | 男人看的网址 | 俄罗斯三级完整版在线观看 | 毛片段| 99视频在线看观免费 | 亚洲精品中文 | 久久久黄色片 | 手机在线观看国产精选免费 | 久九九精品免费视频 | 图片专区亚洲欧美另类 | 国产麻豆流白浆在线观看 | 被夫上司侵犯了中文字幕 | 成人免费国产欧美日韩你懂的 | 69日本xxxxxxxxx98 69人成网站色www | 操双性人| 精品视频在线观看免费 | 成成人看片在线 | 亚洲国产99999在线精品一区 | 女性性色生活片免费观看 |