New Inspections for Java 8 in IntelliJ IDEA 2016.1
Since Java 8 has been launched almost two years ago, it has been gaining more and more traction around the community. Most Java frameworks and platforms have either already migrated their APIs to Java 8, or are planning to do so.
With our latest update, the whole IntelliJ Platform has migrated to Java 8, which has allowed both ourselves and plugin developers to use the new language features. Among other reasons, this motivates us to further improve our coding assistance to make it more friendly to Java 8.
Misuse of java.util.Optional
IntelliJ IDEA now helps you avoid writing unsafe code when using java.util.Optional. It warns you if you call get() without first calling isPresent() to check if the value is available.
Also, you may be warned if you use java.util.Optional<T>, java.util.OptionalDouble, java.util.OptionalInt, java.util.OptionalLong or com.google.common.base.Optional as the type for a field or parameter, or if you use java.util.Optional or com.google.common.base.Optional types with an array or collection type parameter. Note that this setting is disabled by default.
In case a method reference points to a method of its own functional interface type, IntelliJ IDEA suggests replacing it with a qualifier.
You’ll also be warned when you’re calling a method of a functional interface, which is directly invoked on a lambda definition, method reference or anonymous class. This inspection provides a quick-fix to replace it with the implementation body for that functional interface.
Overloaded methods or constructors with similar functional interface type parameters, for which any call sites will need a cast or parameter type specified on the lambda expression to resolve ambiguity, may now be reported as well.
For those who would like to migrate their Guava code to Java 8 APIs, we’ve added a number of quick-fixes that help replace FluentIterable, Function, Optional and Predicate with their Java 8 analogues.
That’s it for today. We hope these improvements will make adopting Java 8 a more enjoyable experience for you.
As always, we appreciate questions as well as your feedback here in comments or directly in our tracker.
The IntelliJ Team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!
The What, Why, and How of JPA Buddy in IntelliJ IDEA
Master JPA entity management with JPA Buddy in IntelliJ IDEA! Our latest article shows you how to simplify your workflow and reduce boilerplate code.
The Best of IntelliJ IDEA’s HTTP Client
In today's fast-paced tech world, easy and efficient management of web services and APIs is crucial. That's where IntelliJ IDEA's HTTP Client steps in, turning complex HTTP requests into a walk in the park. The HTTP Client is a feature-rich, text-based tool in IntelliJ IDEA Ultimate. It seamlessl…
Import Postman Collections to the HTTP Client
We know that many of you use Postman collections and want to stay in the flow while working with them. This means staying inside IntelliJ IDEA and not switching to a different app. Great news! You can now effortlessly transform Postman collections into .http and use them in the HTTP Client …
What’s New in IntelliJ IDEA 2023.1 for Spring Developers
The IntelliJ IDEA 2023.1 release came packed with updates for Spring. This blog post will highlight the most noticeable changes, including full support for Lombok, a reworked Spring tool window, navigation for Spring Security rules, Spring Security 6 support, and more. Remember that these featur…