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.)