Over a million developers have joined DZone.

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.

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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.

Functional Interfaces

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.

Guava

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.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:
spring mvc ,intellij ,jigsaw ,jdk9

Published at DZone with permission of Andrey Cheptcov, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}