Java Series – Java development with JAVA8 new features that's cool. (cont.)

Source: Internet
Author: User

I blog article URL: https://www.peretang.com/using-java8s-new-features-to-coding-is-awesome-2/

Objective

Last week, we talked about the new features of JAVA8, what are functional programming and what are lambda expressions, and let's talk about these new features this week.

This week, we'll talk about what the stream API is and what is optional.

Stream API you make me want to rewrite all my previous code

"Stream API you make me want to rewrite all my previous code", why do I say such a sentence, because when you use the Stream API, you may need one and multiple for loops or For-each loop to complete the work now only need a line to complete.

The previous multithreading of collection types may require a lot of attention, but now you need to turn on a switch to make your operations on the collection type a lot more efficient.

There may be many places to take care of, now you just need to focus on the logic you want to achieve, the rest to the Java8 itself.

In the past, you may have to explain how the operation, code reading is not high, now your code can directly let people "understand" without needing any comments.

Use optional to let your app never take a null pointer exception from here

Optional, is a generic class that indicates whether the object exists and can use the API to determine whether it is empty.

Reference Java8 in action--"

Using optional will force you to more actively dereference the optional object to deal with the problem of missing variable values, and ultimately you will be able to more effectively prevent unexpected null pointer anomalies in your code.

Using Optional can help you design a better API, and users simply need to read the method signature to see if the method accepts a value of type Optional. "

The above is my use of Java8 for a period of time to come to the heart, personal views for reference only.

Pere Tang. 0AM on July 15, 2017

Reference

Java 8 in Action

This article from "Pere Tang" blog, reproduced please contact the author!

Java Series – Java development with JAVA8 new features that's cool. (cont.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.