Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to autocomplete lambdas in IntelliJ IDEA?

I'm using IntelliJ IDEA 13 with Java 8 and wonder how to autocomplete lambdas. Before Java 8 I used anonymous inner classes of course. I auto completed by typing "new" and hitting Ctrl+Space:

autocomplete new

and choosing the first option.

Now with Java 8 I want to generate lambdas as well, inferring parameters and all, but I can't find autocompletion for it.

Note, this above example is quite easy, but when you have multiple parameters with generic types, e.g. JavaFX Listeners and the like, autocompletion comes in handy.

like image 953
Tim Büthe Avatar asked Aug 07 '14 12:08

Tim Büthe


People also ask

How do I turn on autocomplete in IntelliJ?

By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.

Why Autocomplete is not working in IntelliJ?

I have tried the following according to this thread (Intellij IDEA CE 12 Android XML Code Completion not working): Go to File->Power Save Mode and disable it - it is off. Go to Preferences->Editor->Code Completion and check Autopopup code completion - this has been checked. Go to File->Invalidate Caches and restart.

How do I get suggestions on IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | General | Code Completion. To automatically display the suggestions list, select the Show suggestions as you type checkbox.

How do you evaluate lambda expression in IntelliJ?

Start the IDE, Help | Find Action (Ctrl+Shift+A or Cmd+Shift+A on Mac), type "Switch IDE Boot JDK", press Enter. Start the IDE, use Help | Find Action (Ctrl+Shift+A or Cmd+Shift+A on Mac), type "Switch IDE Boot JDK", press Enter. Switch IDE Boot JDK dialog appears.


2 Answers

In Windows or Linux, it’s Ctrl+Space

In Mac OS, it’s Ctrl+Shift+Space

enter image description here

like image 53
Tim Büthe Avatar answered Sep 28 '22 02:09

Tim Büthe


You can just type p = s -> f..., autocompletion will then suggest false. If you're not sure about lambda, you can start with the inner class, and then turn it into a lambda expression.

In your example you can press Alt+Enter afterwards, as follows:

After completing:

After completing

After pressing Alt+Enter:

After pressing Alt+Enter

Result:

Result

Clicking the small icon at the gutter shows you the Predicate.test method. Override icon at gutter

like image 31
sina72 Avatar answered Sep 28 '22 02:09

sina72