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

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

idea 模板編程知識小結(jié)

瀏覽:62日期:2024-08-19 18:31:51

模板編程是idea的強(qiáng)大功能,也提高了開發(fā)人員的編程效率,比如輸入main函數(shù):

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

正常情況下我們需要每個(gè)字母挨個(gè)輸入,但是這樣輸入太慢了,有了模板編程,我們只需要輸入psvm或者main,然后回車,就會輸出

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

,是不是大大的提高了編碼速度。這里對模板編程進(jìn)行簡單的介紹。

一、模板編程簡介

模板編程的位置如下圖:File-->settings-->Editor

其中,Editor-->General-->Postfix Completion 和 Editor-->Live Templates下面都有模板編程的配置,不同的是Live Templates下的模板是可以新建和修改的

idea 模板編程知識小結(jié)idea 模板編程知識小結(jié)

java編程常用的模板我在上圖中標(biāo)注出來了

二、常用模板

先介紹一下常用的、idea自帶的模板

1. static final 變量

prsf: private static final

psf: public static final

psfi: public static final int

psfs: public static final String

2. main函數(shù)

psvm/main: public static void main(String[] args) { }

3. for循環(huán)

fori: for (int i = 0; i < ; i++) { }iter: for (String arg : args) { }itar: for (int i = 0; i < args.length; i++) { String arg = args[i]; }

4. list循環(huán)

List<String> stringList = new ArrayList<>();

stringList.fori: for (int i = 0; i < stringList.size(); i++) { }

stringList.for: for (String s : stringList) { }

stringList.forr: for (int i = stringList.size() - 1; i >= 0; i--) { }

5. 其他

假設(shè)有這樣的對象

Producer producer = new Producer();

則對象判空:

ifn: if (producer == null) { } inn: if (producer != null) { } // xxx.nnproducer.nn: if (producer != null) { } // xxx.nullproducer.null: if (producer == null) { }

sout:System.out.println();

idea常用模板編程效果:

模板編程: public class TemplateTest { // prsf private static final int a=10; //psf public static final int b=10; //psfi public static final int c=1000; // psfs public static final String d='qqq'; // psvm public static void main(String[] args) { System.out.println('hello'); // soutm System.out.println('TemplateTest.main'); // soutv int n=10; System.out.println('n = ' + n); // xxx.sout int num=100; System.out.println(num); // souf System.out.printf(''); // for循環(huán) //fori for (int i = 0; i <100 ; i++) { // i.sout System.out.println(i); //i.soutv System.out.println('i = ' + i); // i.switch switch (i) { } } // iter for (String arg : args) { } // itar for (int i = 0; i < args.length; i++) { String arg = args[i]; } List<String> stringList = new ArrayList<>(); // stringList.fori for (int i = 0; i < stringList.size(); i++) { } // stringList.for for (String s : stringList) { } // stringList.forr for (int i = stringList.size() - 1; i >= 0; i--) { } Producer producer = new Producer(); // ifn if (producer == null) { } // inn if (producer != null) { } // xxx.nn if (producer != null) { } // xxx.null if (producer == null) { } // inst if (producer instanceof Object) { Object o = (Object) producer; } }}

我們可以通過快捷鍵 ctrl+j 來查看模板編程提示:

idea 模板編程知識小結(jié)

更多的idea編程模板可以去Live Templates下面查看

三、模板自定義與修改

我們可以在Live Templates 位置下自改和自定義模板

1. 修改

比如對psfi進(jìn)行修改

修改前:

psfi: public static final int

idea 模板編程知識小結(jié)

修改后:

psfi:public static final int i =

idea 模板編程知識小結(jié)

2. 自定義模板

可以通過選擇右邊的+自定義模板,步驟如下:

idea 模板編程知識小結(jié)

idea 模板編程知識小結(jié)

模板里面的$var$是生成時(shí)光標(biāo)停留的位置

idea 模板編程知識小結(jié)

點(diǎn)擊define,選擇應(yīng)用范圍(沒有此步驟,模板不生效),這里選擇Java,則勾選Java

idea 模板編程知識小結(jié)

自定義效果:

// test public void test(){ }

總結(jié)

到此這篇關(guān)于idea 模板編程的文章就介紹到這了,更多相關(guān)idea 模板編程內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: IDEA
相關(guān)文章:
主站蜘蛛池模板: 红安县| 开封市| 稷山县| 松桃| 新蔡县| 依兰县| 汶上县| 利辛县| 栾川县| 会昌县| 柘荣县| 集安市| 邹平县| 广西| 青神县| 宜春市| 洛隆县| 彭阳县| 安仁县| 安岳县| 冕宁县| 温泉县| 贵南县| 邵武市| 长汀县| 阜宁县| 繁峙县| 铁岭市| 乌苏市| 淄博市| 克山县| 资源县| 濮阳市| 岳池县| 额敏县| 黄浦区| 东丽区| 祁东县| 湘阴县| 喜德县| 濮阳县|