Early Access Program Features

IntelliJ IDEA 2016.3 EAP Helps Migrate to Java 8’s Stream APIs

In one of her recent articles, Trisha Gee wrote about refactoring to Java 8. Among many great tips about Java 8, the article also showed how IntelliJ IDEA helps write correct and idiomatic Java 8. With IntelliJ IDEA 2016.3, we’ve gone further and extended our existing inspections to support non-trivial cases.

Now, if you click Alt+Enter inside a for-loop incrementing a local variable defined above, the IDE will prompt you to replace it with a chain of the steam API calls ending with count(). Note, if the loops are nested, the IDE will use flatMap():

If the variable is incremented by a number returned from another method, the IDE will use the mapToInt()/mapToLong()/mapToDouble():

If, instead of incrementing a variable, the loop adds non-primitive objects to a collection, the IDE will replace it with a chain of calls ending with collect():

If the object being added to the collection is a result of another method, the IDE will handle it in an idiomatic way by using map():

How non-trivial the code supported by these inspections could be? Quite much. Consider a loop that heavily uses a continue statement:

Similar to continue, the IDE will correctly handle return statements too, using anyMatch():

If you decide to use these inspections, make sure to adjust the default Code Style settings to avoid exceeding the right margin for long method chains. Here, you have a choice, depending on your preferences.

  • Chop down chain method calls if they’re long (most preferable for Java 8)

2. Wrap method call arguments

At the moment we’re considering changing these defaults. If have ideas how to do it with no harm to existing users, let us know.

The inspections are enabled by default but their severity is set to the minimum–which means no warnings. This is yet another new feature of IntelliJ IDEA 2016.

You can change the severity of any inspection in the Settings:

If you want, you can apply these inspections in the batch mode on a scope of your choice:

We hope the new inspection will help you make your Java 8 code write even more idiomatic and take the most out of the stream API. Those unfamiliar yet with the stream API, make sure to read Oracle’s tutorials: part 1 and part 2.

The last but not least, we’re also working to improve the layout of VCS Log:

  • Commit details have moved to the right, giving more space to the Log itself.
  • Commit messages in the table are now aligned and thus more readable.
  • More changes are yet coming.

That’s it for today. To give the new features a try, download the EAP build. Don’t forget to write us back (using our issue tracker) about your impressions and bugs if any.

Develop with Pleasure!

Comments below can no longer be edited.

10 Responses to IntelliJ IDEA 2016.3 EAP Helps Migrate to Java 8’s Stream APIs

  1. Avatar

    Onno van Paridon says:

    September 13, 2016

    Great news the the VCS log is getting some attention. Can you comment if ‘Cherry picking’ for SVN (https://youtrack.jetbrains.com/issue/IDEA-99578) is also on the list of coming changes?

  2. Avatar

    Paul says:

    September 14, 2016

    I’m having issues with this upgrading – I press Update and Restart, the IDE closes down and nothing happens. It doesn’t upgrade. I’m on OSX. Any ideas?

  3. Avatar

    Al Sweetman says:

    September 14, 2016

    Sounds great – I notice in the video at the top that there is a “not equals” symbol rather than the “standard” != … is this just a font choice or is there some other EAP magic going on? Likewise for the -> being displayed as a proper arrow?

  4. Avatar

    nafg says:

    September 14, 2016

    Amazing stuff. Any chance this refactorings will be supported in Scala?

  5. Avatar

    Updater says:

    September 21, 2016

    Yet we still can’t simply update to this version: IntelliJ shows only the “download” button instead of “download and upgrade” :(.

  6. Avatar

    Brandon Johnson says:

    September 26, 2016

    I wonder if we might be able to get an automatic refactoring for building a map?

    private Map getPeople() {
    List people = peopleMapper.getPeople();
    Map idToName = new HashMap();
    for (Person person : people) {
    int id = person.getId();
    String name = person.getName();
    idToName.put(id, name);
    return idToName;

  7. Avatar

    GourdErwa says:

    January 11, 2017


Discover more