Java 8 and Method References in IntelliJ IDEA 12

Posted on by Anna Kozlova

As you might know IntelliJ IDEA 12 will bring support for new features of Java 8 language. Though this is still in progress, you can try some of these features now in IntelliJ IDEA 12 EAP.

Here we would like to provide some details on method and constructor refereces support.

IntelliJ IDEA as always provides a way to transform existing code to use new features. Dedicated inspection finds and highlights anonymous types which can be replaced with a method reference.

After you apply provided quick-fix, it gets just a line of code.

There is also another inspection that checks if a lambda expression in your code can be replaced with a method reference.

You can also use an intention  to replace a method reference with a lambda expression, in the case when you need additional logic.

All the common features such as completion, refactorings, formatting and many other were updated to support method and constructor references.

As always you are very welcome with suggestions and feedback in our issue tracker.

Develop with Pleasure!

Comments below can no longer be edited.

6 Responses to Java 8 and Method References in IntelliJ IDEA 12

  1. Alexandre Verri says:

    October 22, 2012

    No way to use this version. Every time I got “window blue screen of the death”. I’m using Windows 7 64 bits, JVM 1.7.0_09 64 bits.

    • Zizzi Topper says:

      September 14, 2015

      Do you mean java 7 with IDEA crashes your Windows? Sounds funny 🙂

    • Adel Helal says:

      February 24, 2017

      Makes zero sense because blue screen of death comes from a hardware driver failure.
      Must have been unrelated to IntelliJ which is just a software application.

  2. Aaron Scott-Boddendijk says:

    October 23, 2012

    Do we have to launch the IDE from one of the Lambda builds to experiment with this?

    Available at http://jdk8.java.net/lambda/

  3. Anna Kozlova says:

    October 23, 2012

    Aaron, you don’t need to start IDEA on jdk 8, but you need to configure JDK for your project to use JDK 8 with lambda support.
    Thanks

  4. Herman Bovens says:

    June 10, 2015

    Refactoring from lambda to method reference is actually not (always) correct.


    () -> instance.call()

    is not the same as


    instance::call

    when instance is a member variable whose value may have changed by the time the lambda is called. If instance is null at this point in the code, the latter will even cause an NPE immediately.

Subscribe

Subscribe for updates