Eclipse Support for Java 8

Last week Java 8 was launched and moments later the Eclipse support for Java 8 was announced. To help celebrate the launch, we had an entire Java 8 Day at EclipseCon 2014, which included sessions from both Java and Eclipse engineers. Highlights for me included hearing Alex Buckley describe the Road to Lambda, listening to John Arthorne talk about API Design in Java 8 and watching the Eclipse Java Development Tools (JDT) Team present all the great work they did on Java 8 Tooling in Eclipse.

Java 8 is available as an update for Eclipse Kepler (2013 Release) and is now available nightly / integration builds towards Eclipse Luna (2014 Release). For details about how to get Java 8 support in Eclipse, please read to the bottom of this post.

New and Noteworthy

For those of you who were not lucky enough to join us in San Francisco, here is a summary of the Eclipse Support for Java 8.

Screen Shot 2014 03 24 at 3.45.13 PM Eclipse Support for Java 8

The Eclipse Java Compiler (EJC) now supports Java 8 and the tools are well integrated. There are quick-fixes, for converting anonymous inner classes (with a single method — i.e. functional interfaces) to a lambda expression:

Screen Shot 2014 03 24 at 3.43.37 PM Eclipse Support for Java 8

As well as ones for converting back, or even changing the body expression to a block (ctrl+1):

Screen Shot 2014 03 24 at 3.48.02 PM Eclipse Support for Java 8

And in-line refactoring support :

Screen Shot 2014 03 24 at 6.56.59 PM Eclipse Support for Java 8

There are Code Formatter options for lambda expressions such as ones that describe how the expression should be wrapped:

Screen Shot 2014 03 24 at 3.50.40 PM Eclipse Support for Java 8

And code clean-up actions which will convert the uses of anonymous classes to lambdas where possible. Simple enable this, and select Source -> Clean Up to automatically update your current code to use lambdas.

Screen Shot 2014 03 24 at 3.55.44 PM Eclipse Support for Java 8

The debugger supports breakpoints in lambdas as well as the variable view, and stack frame inspection:

debug Eclipse Support for Java 8

While lambda support was clearly the most visible change in Java 8, there are a number of other features too. Features such as default methods (method bodies in your interfaces), better type inference and effectively final variables are all supported:

Screen Shot 2014 03 26 at 9.10.31 AM Eclipse Support for Java 8

Finally, Java 8 supports type annotations and Eclipse ships with a set of annotations for null analysis. For example, you can specify that a List should never be null, and each element of the list should also never be null. The JDT will provide compile time type checking to ensure this constraint holds.

nonnull Eclipse Support for Java 8

This provides API designers with the facilities to create better interfaces with stricter rules about what can be passed to and returned from an API.

api Eclipse Support for Java 8

Java 8 represents one of the biggest Java releases ever. The JDT team should be really proud of the great work they did to support Java 8 in Eclipse.

For more information on Eclipse and Java 8, checkout Holger’s article on Java 8 and SWT.

Feel free to follow me (@irbull) on Twitter for more Eclipse updates.

[ Looking for tools? See our Eclipse Tools page. | Managing your Eclipse workspaces is easier with Yoxos. Create a free profile now. ]

Getting Java 8

Java 8 is available in builds towards Eclipse Luna (2014 Release coming in June) and as an update for Eclipse Kepler (2013 Release). To develop Java 8 applications, you will first need to install a Java 8 JDK.

If you are using Eclipse Kepler:

  1. Make sure you are using Eclipse Kepler SR2
  2. Help -> Install new Software
  3. Add the following URL to the works with field
    http://download.eclipse.org/eclipse/updates/4.3-P-builds/
  4. Choose the category “‘Eclipse Java 8 Support (for Kepler SR2)”
  5. Deselect “Contact all updates sites during install”
  6. Click Next and follow the wizard
  7. Restart Eclipse when prompted

If you are using Eclipse Luna:

  1. Add the update site that contains Integration Builds Towards Luna
    http://download.eclipse.org/eclipse/updates/4.4-I-builds
  2. Check for updates
  3. Follow the prompts and restart Eclipse when prompted
    or, visit the Downloads Page and download Eclipse with a version >= 20140318

14 Responses to “Eclipse Support for Java 8”

  1. Eike Stepper says:

    Hi Ian, Nice summary! But isn’t the Quick Fix key ctrl+1 (not F1)?

  2. Ian Bull says:

    Ha! There likely isn’t a key combination I use more, and I still got it wrong. Funny how I just use it without thinking. Thanks Eike, I’ll update the post.

  3. R says:

    Seems a bit strange to say that Eclipse supports Java 8 when most people are using maven projects – and maven projects will require the Java 8 Facet which is not yet available. So I don’t think Eclipse can really say they support Java 8 yet…

  4. Ian Bull says:

    @R
    I’m not sure I agree with the statement that since there is an Eclipse plug-in (m2e in this case) that doesn’t support Java 8, Eclipse doesn’t support Java 8. Having said that, the projects are currently working on a co-ordination strategy for all Java 8 related work. I’ll keep everyone updated as that work proceeds.

  5. JOKe says:

    the interface WTF example is wrong :)

  6. R says:

    @Ian

    With how popular maven based build systems are, should they not be part of core Eclipse to start with? The other major IDEs have all moved in that direction and it might be hurting the popularity of Eclipse to require plugins to use Maven.

    In practice I’m pretty sure most eclipse developers are running the maven plugins anyway?

  7. R says:

    Just to add: I don’t really like maven myself, but today if you want to use any OSS Java libraries (and considering how good they are, that means everyone using Java) it’s almost a requirement that you utilize maven.

  8. Ian Bull says:

    @JOKe
    Thanks! Fixed it.

  9. Srihari KonaKanchi says:

    Hi Ian
    In your example you mentioned run method using outer field though not defining as ‘final’, it means a closure right?

    Srihari Konakanchi

  10. Gaurav Bajpai says:

    Very nice and simple steps to get Java 8. Thanks for this superb article. @Ian Bull

  11. Javin says:

    Good to know that now Eclipse is also supporting Java 8. I really find Netbeans content assist on use of lambda expressions in Java 8 effective which also adds onto your learning. Looking forward for better support and content assist in Eclipse.

    Regards
    Javin

  12. Richard Steiger says:

    Given the recent announcements of both the Kepler patch and the 4.4 build, I was looking forward with great excitement to start doing some Java 8 development, and if it went smoothly, to start migrating my firm’s code-base to Java 8.

    Unfortunately, I’ve encountered what’s effectively a show-stopper bug: with jdk1.0.8_05 selected as the default JRE, opening a type hierarchy on a few JDK classes (Set, Collection, Consumer) reliably fails, with the message ‘Computing type hierarchy of has encountered a problem.’ The error log show an NPE being thrown (and BTW, in Luna, the stack trace is missing from the error log). This happens in both the updated Kepler (4.3.2 with the Java 8 update), and the latest Luna (4.4RC4) download. In both versions, with jdk1.7.0_60 set as the default JRE, no such problem occurs.

    As I indicated, this behavior renders eclipse unusable for our Java 8 migration project (our code base contains well over 25K classes, hence, navigating type hierarchies is one of our most heavily-used tools).

    I was unable to find any eclipse bugs fitting this symptom. If this seems like a new bug to any of you, please let me know and I’ll submit one (hints on best submission practice would be appreciated).

    Thanks much,

    -rjs

    -rjs

  13. Richard Steiger says:

    I tried a different search pattern, and did find Bug 425111 (still open), which fits the symptoms, but not conditioned on Java 8 being the default JRE. I’ll add the above info to the bug.

    -rjs

  14. Ian Bull says:

    @Richard

    Thanks for updating the bugzilla entry with your information. Stephan Herrmann is a really smart guy, so hopefully this issue will get sorted out.

14 responses so far

Written by . Published in Categories: EclipseSource News, Editors choice, Planet Eclipse