File tree Expand file tree Collapse file tree
src/main/java/io/github/aplotnikov/java_8_misuses/lambda Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package io .github .aplotnikov .java_8_misuses .lambda ;
2+
3+ import java .util .Optional ;
4+
5+ import static io .github .aplotnikov .java_8_misuses .utils .Annotations .Good ;
6+ import static io .github .aplotnikov .java_8_misuses .utils .Annotations .Ugly ;
7+
8+ class LambdasAreNotAlwaysTheBestOption {
9+
10+ @ Ugly
11+ class UnneededLambdasUsage {
12+ void processAndPrint (String name ) {
13+ Optional .ofNullable (name )
14+ .map (s -> s .toUpperCase ())
15+ .map (s -> doProcess (s ))
16+ .ifPresent (s -> System .out .print (s ));
17+ }
18+
19+ private String doProcess (String name ) {
20+ return "MR. " + name ;
21+ }
22+ }
23+
24+ @ Good
25+ class MethodReferenceUsage {
26+ void processAndPrint (String name ) {
27+ Optional .ofNullable (name )
28+ .map (String ::toUpperCase )
29+ .map (this ::doProcess )
30+ .ifPresent (System .out ::print );
31+ }
32+
33+ private String doProcess (String name ) {
34+ return "MR. " + name ;
35+ }
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments