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.