Intellij IDEA – in my opinion the most productive IDE for Java – comes with bunch of features helping getting rid of writing repetitive code – which is a everyday business no matter what language you use. One of them is live templates.

Live templates contain predefined code fragments. You can use them to insert frequently-used or custom code constructs into your source code file quickly, efficiently, and accurately.

IDEA comes with a set of live templates for Java, Maven, HTML, CSS and more and also enables to create custom templates.

Inserting live template

There are 2 ways to insert live template:

  1. Type live template abbreviation (for example dep) and next press TAB key
  2. Use shortcut Command + J (Mac) / Ctrl + J (PC) to popup list of available live templates in current context

At the beginning it’s quite difficult to remember all you wish to use and going back and forth from code to settings or browsing list is not very efficient – especially when you don’t know what you are looking for. That’s why I created gallery of (in my opinion) most useful built-in live templates for Java and Maven that can be used as a cheat sheet:

Maven

  • dep – Inserts <dependency/>

  • pl – Inserts <plugin/>

  • repo – Inserts <repo/>

Iterations

  • fori – creates iteration loop

  • itar – iterates elements of array

  • itco – iterates elements of java.util.Collection

  • iter – iterates Iterable

  • itit – iterates java.util.Iterator

  • itli – iterates elements of java.util.List

Other

  • ifn – Inserts “if null” statement

  • inn – Inserts “if not null” statement

  • inst – Checks object type with instanceof and down-casts it

  • lazy – Performs lazy initialization

Plain

  • psf – public static final

  • psfi – public static final int

  • psfs – public static final String

  • thr – throw new

Summary

Using predefined Java templates is just a beginning. You can find ready to use templates for particular frameworks on Github and I really encourage you to create your custom, project specific ones.

If you created interesting common use live templates for Java or related frameworks feel invited to post them in comments.

Code faster with Intellij IDEA live templates的更多相关文章

  1. Error during generated code invocation: com.intellij.debugger.engine.evaluation.EvaluateException: Method threw 'java.lang.IllegalAccessError' exception.

    场景描述: 再从该数据库中读取数据进行处理的时候,需要将某个字段加入到一个动态的map中,然后需要对该map进行filter过滤,在执行过滤方法的时候报错 Error during generated ...

  2. 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键

    google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...

  3. Code Complete阅读笔记(三)

    2015-05-26   628   Code-Tuning Techniques    ——Even though a particular technique generally represen ...

  4. 使用IntelliJ IDEA开发前的基本设置,有助于提高开发效率

    2.界面字体大小设置 File菜单->Settings->Appearance->Override default fonts by(not recommended): Name:宋 ...

  5. Code Complete阅读笔记(二)

    2015-03-06   328   Unusual Data Types    ——You can carry this technique to extremes,putting all the ...

  6. Java Code Style

    近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...

  7. PatentTips - Method and Apparatus to Support Virtualization with Code Patches

    BACKGROUND As recognized in Revision 2.0 of the Intel® Virtualization Technology Specification for t ...

  8. R-CNN, Fast R-CNN, Faster R-CNN, Mask R-CNN

    最近在看 Mask R-CNN, 这个分割算法是基于 Faster R-CNN 的,决定看一下这个 R-CNN 系列论文,好好理一下 R-CNN 2014 1. 论文 Rich feature hie ...

  9. IntelliJ IDEA 配置《算法》(第四版)

    红皮的算法一书,内部代码的实现调用了作者写的一个包.为了运行书内代码,需要配置相应的环境. 准备 网站:https://algs4.cs.princeton.edu/code/ 工具:IntelliJ ...

随机推荐

  1. btrace-dtrace-for-java-ish

    http://dtrace.org/blogs/ahl/2012/04/24/btrace-dtrace-for-java-ish/

  2. Html学习笔记3

    1表格的标题和表头: <table> <caption>成绩单</caption> <tr> <th>姓名</th> <t ...

  3. Task.Delay方法的2个应用实例,单元测试等待,限时限次下载远程资源

    如果想让程序异步等待一段时间,可以考虑使用Task.Delay方法. 比如,在单元测试中模拟一个异步操作. static async Task<T> DelayedResult<T& ...

  4. 内存加载DLL

    1.前言 目前很多敏感和重要的DLL(Dynamic-link library) 都没有提供静态版本供编译器进行静态连接(.lib文件),即使提供了静态版本也因为兼容性问题导致无法使用,而只提供DLL ...

  5. Java 获取客户端IP

    像移动网关一样,iisforward这个ISAPI过滤器也会对request对象进行再包装,附加一些WLS要用的头信息.这种情况下,直接用request.getRemoteAddr()是无法取到真正的 ...

  6. javascript游戏引擎

    基于JavaScript开发的游戏是唯一一个能够跨桌面,Web和移动三种平台的.今天,本文向大家推荐一些非常棒的JavaScript游戏开发框架. AD:干货来了,不要等!WOT2015 北京站演讲P ...

  7. 让手机连接到指定的WIFI网络,适用于之前已经连过的网络

    这个例子是从网上找的,我给重新优化了下.这里有个问题是只能连接到之前已经连接过的wifi,目前还没找到连接到陌生wifi(有/无密码)的方法.总之慢慢来吧~ 说下思路: 1.通过wifiManager ...

  8. modbus.c

    #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> //#include ...

  9. Bias(偏差),Error(误差),和Variance(方差)的区别和联系

    准: bias描述的是根据样本拟合出的模型的输出预测结果的期望与样本真实结果的差距,简单讲,就是在样本上拟合的好不好.要想在bias上表现好,low bias,就得复杂化模型,增加模型的参数,但这样容 ...

  10. Chart:ECharts

    ylbtech-Chart:ECharts ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome, ...