国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:10日期:2024-08-17 09:31:48

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

//beforepublic class Foo { void m(boolean b) { m(b!); } } //afterpublic class Foo { void m(boolean b) { m(!b); }}

if: Checks boolean expression to be ’true’

//beforepublic class Foo { void m(boolean b) { b.if }}//afterpublic class Foo { void m(boolean b) { if (b) { } }}

else: Checks boolean expression to be ’false’.

//beforepublic class Foo { void m(boolean b) { b.else }}//afterpublic class Foo { void m(boolean b) { if (!b) { } }}

3.2. array 變量模板

for: Iterates over enumerable collection.

//beforepublic class Foo { void m() { int[] values = {1, 2, 3}; values.for }}//afterpublic class Foo { void m() { int[] values = {1, 2, 3}; for (int value : values) { } }}

fori: Iterates with index over collection.

//beforepublic class Foo { void m() { int foo = 100; foo.fori }}//afterpublic class Foo { void m() { int foo = 100; for (int i = 0; i < foo; i++) { } }}

3.3. 基本類型模板

opt: Creates Optional object.

//beforepublic void m(int intValue, double doubleValue, long longValue, Object objValue) { intValue.opt doubleValue.opt longValue.opt objValue.opt}//afterpublic 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.

//beforepublic class Foo { void m(boolean b) { b.sout }}//afterpublic class Foo { void m(boolean b) { System.out.println(b); }}

3.4. Object 模板

nn: Checks expression to be not-null.

//beforepublic class Foo { void m(Object o) { o.nn }}//afterpublic class Foo { void m(Object o) { if (o != null){ } }}

null: Checks expression to be null.

//beforepublic class Foo { void m(Object o) { o.null }}//afterpublic class Foo { void m(Object o) { if (o != null){ } }}

notnull: Checks expression to be not-null.

//beforepublic class Foo { void m(Object o) { o.notnull }}//afterpublic class Foo { void m(Object o) { if (o != null){ } }}

val: Introduces variable for expression.

//beforepublic class Foo { void m(Object o) { o instanceof String.var }}//afterpublic class Foo { void m(Object o) { boolean foo = o instanceof String; }}

3.5. 其他模板

new: Inserts new call for the class.

//beforeFoo.new//afternew Foo()

return: Returns value from containing method.

//beforepublic class Foo { String m() { 'result'.return }}//afterpublic class Foo { String m() { return 'result'; }}

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

標簽: IDEA
相關(guān)文章:
主站蜘蛛池模板: 广河县| 湘阴县| 金溪县| 壤塘县| 吉木乃县| 驻马店市| 宝丰县| 平安县| 虎林市| 潼关县| 尤溪县| 哈巴河县| 河曲县| 家居| 临澧县| 鹤峰县| 丁青县| 高雄市| 长寿区| 永胜县| 古蔺县| 鄂托克前旗| 黑龙江省| 沭阳县| 托克逊县| 资源县| 普兰店市| 昆明市| 南开区| 双城市| 韩城市| 新化县| 平邑县| 修武县| 兴城市| 汽车| 土默特右旗| 安溪县| 英吉沙县| 浦东新区| 巴林左旗|