The following are the new features of Java 8 that I commonly use (sorted by frequency of use) 1. lamda expressions; 2. Streams; 3. Method references; 4. Default and static methods of interfaces;
Above, 1 and 2 are artifacts. I don’t want to explain them. However, it will feel a bit awkward at first because you are not used to them. Later, when you get used to them, writing code will feel like flying. (However, if you use it improperly, you can still write a shit (this is a human problem, anyone Language is inevitable), and in some scenarios the readability may not be better than traditional writing). If you are proficient in using 3, some things that could only be achieved using reflection in the past can also be achieved through method references. It is recommended to become familiar with itFunction, Consumer, Predicate, Supplier. 4 is considered to enhance the interface, and it is not used very much.
Others are less used, but it is worth mentioning Date/Time API,试用了一下,的确比旧版的API好用和方便,感觉跟Joda time很相似了。奈何新版API的对象跟原有的Date、Time对象之间的转换却十分麻烦,加上公司一早就使用上了Joda Time,所以也就没怎么用新版的Date/Time API.
The following are the new features of Java 8 that I commonly use (sorted by frequency of use)
1. lamda expressions;
2. Streams;
3. Method references;
4. Default and static methods of interfaces;
Above, 1 and 2 are artifacts. I don’t want to explain them. However, it will feel a bit awkward at first because you are not used to them. Later, when you get used to them, writing code will feel like flying. (However, if you use it improperly, you can still write a shit (this is a human problem, anyone Language is inevitable), and in some scenarios the readability may not be better than traditional writing).
If you are proficient in using 3, some things that could only be achieved using reflection in the past can also be achieved through method references. It is recommended to become familiar with it
Function, Consumer, Predicate, Supplier
.4 is considered to enhance the interface, and it is not used very much.
Others are less used, but it is worth mentioning
Date/Time API
,试用了一下,的确比旧版的API好用和方便,感觉跟Joda time
很相似了。奈何新版API的对象跟原有的Date、Time
对象之间的转换却十分麻烦,加上公司一早就使用上了Joda Time
,所以也就没怎么用新版的Date/Time API
.The company uses 1.7, and when I play by myself, I use 1.8
If it weren’t for Java 8, I would be too lazy to use Java.