IntelliJ shortcut to insert null check?

Is there a shortcut to insert code:

if (someParameter == null) throw NullPointerException("someParameter is null"); 
+6
java intellij-idea keyboard-shortcuts code-completion
source share
5 answers

Try ifn and then Tab. You can find more of those or define your own by going to the settings and searching for "Live Templates".

+15
source share

IntelliJ IDEA provides other shortcut-like functionality that can help with your performance, namely Postfix completion .

If you want to insert a null check, enter ".null" after the variable name, for example

postfix completion

and zero code will be inserted automatically, for example

null check code

IntelliJ IDEA provides more convenient postfix replenishment, which you can find in the settings in Editor> General> Post-completion

Postfix completion

+5
source share

There is no template for this, but you can easily create one. Just follow the instructions here .

+3
source share

Now there is an easy way to do this (in version 13.1), described here: http://blog.jetbrains.com/idea/2014/03/postfix-completion/

+3
source share

If everything is fine with the comments in the code, you can try the solution mentioned here . It does not solve the problem directly, but if you have such zero checks in many places, you can use this :)

0
source share

All Articles