Postfix Completion in IntelliJ IDEA

It’s not a secret that my favorite IDE is IntelliJ IDEA. There are so many features, nobody (?) knows all of them. A few days ago I „discovered“ the postfix completion and want to share my knowledge with you.

The basic idea is, that sometimes you forget to start an expression with the right term. Then you can add a post completion string and IntelliJ IDEA transform the expression in the right shape. jetbrains explains the post completion in this article.

Here are some examples that I use often:

Null or Not Null?

You want to do a null check of a variable? Simply enter the name of the variable and add „.null“

and the result is

Or if you want to make sure that a variable is not null? Enter „.nn“

and you get

For loop

You don’t want to enter a for loop all by yourself? Just write the name of the collection and add „.for“

then you’ll get

Try

After you’ve typed a variable declaration you remembered that this can throw an exception that you want to catch. Simply type „.try“ and get the try-catch-block for free

and the result is:

Other languages

Postfix completion is not only available for Java but also for JavaScript, Scala and Kotlin (at least in 2017.1). Most of the commands mean the same but there are language specific commands like „.val“ for Kotlin.

Next steps

As you can see, postfix completion is worth another look. So don’t hesitate to find the completions you like most.

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.