????1. ????Streams??????????????????
????Java8??????????????????????–???С?parallelStream() ?????????????????????С???????????????????????????????????д??????Щ??????????????CPU?????????????????????????????????????fork/join?????e??????????????????????????????????ò???????????????????????
?????????????ò?????????????????????????е????????????????Щ???????????????15%???????????????????????????????????????????.parallelStream() ???????????????????У????????????????CPU??????????????????????????л?????????????嶼???????
??????????????????????????饗???/??????????
????Map<Boolean?? List<Integer>> groupByPrimary = numbers
????.parallelStream().collect(Collectors.groupingBy(s -> Utility.isPrime(s)));
????????????????п???????????????????????????????????????????????????????Щ??????????????????????????.parallelStream() ?????????????????????????????????????????????????????£? Lukas Krecan???????Щ???????? ??
????????????д????????????????????????Щ??????????????????????????????????????????????????????????????????л????
????2. Lambda ?????????
????lambda?????????lambda?????????lambda?????????????????????????飬????lambda?????????????????????????????????????lambda?????????????????????????籭?????????????????????????????????????????????254??????
????List lengths = new ArrayList();
????for (String countries : Arrays.asList(args)) {
????lengths.add(check(country));
????}
??????????????????????lambda??????????????????
????Stream lengths = countries.stream().map(countries -< check(country));
????????!????????????????????Щ??lambda?????????????????Java???У??????????????????????£??????????????????Java?????淶???????????????????????????lambda????? ??????????????????????????????????????????????lambda????????????????Tal Weiss????????
???????????????????д????????????????????????????????????????????????????Щ???????????????????????????list?У????????????????????????
????at LmbdaMain.check(LmbdaMain.java:19)
????at LmbdaMain.main(LmbdaMain.java:34)
?????????????
at LmbdaMain.check(LmbdaMain.java:19)
at LmbdaMain.lambda$0(LmbdaMain.java:37)
at LmbdaMain$$Lambda$1/821270929.apply(Unknown Source)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.LongPipeline.reduce(LongPipeline.java:438)
at java.util.stream.LongPipeline.sum(LongPipeline.java:396)
at java.util.stream.ReferencePipeline.count(ReferencePipeline.java:526)
at LmbdaMain.main(LmbdaMain.java:39
????lambda????????????????????????????????????????????????????Щ???Σ???Щ???????????????????????????????Щ????μ????Щ???????????á?Lukas Eder ???????????????????
???????????????????????????????????????????????????????????lambda??????
????3. Default???????????
????Default???????????????????????????????????????Java8???????п?????????????????????????????Щ???????????????????????default???????????????????
????Defalut????????????????????????????????е????????????????????????????д????????????????????????汾????????磬?????????Oracle Java????? ?????????????????????????
public interface TimeClient {
// ...
static public ZoneId getZoneId (String zoneString) {
try {
return ZoneId.of(zoneString);
} catch (DateTimeException e) {
System.err.println("Invalid time zone: " + zoneString +
"; using default time zone instead.");
return ZoneId.systemDefault();
}
}
default public ZonedDateTime getZonedDateTime(String zoneString) {
return ZonedDateTime.of(getLocalDateTime()?? getZoneId(zoneString));
}
}
??????????????????ж???????????????Default?????????????????????????????????????????????????????????????????μ????????????????????Oleg Shelajev??RebelLabs?????????°ɡ?
????????????????????????????????????????????????????????÷???????????????????????μ?????????????????