3
3
import com .java15 .example .modern_java_in_action .Apple ;
4
4
import com .java15 .example .modern_java_in_action .Colors ;
5
5
6
+ import java .util .ArrayList ;
6
7
import java .util .Arrays ;
7
8
import java .util .Comparator ;
8
9
import java .util .List ;
@@ -18,7 +19,25 @@ public static void main(String[] args) {
18
19
//extracted2();
19
20
//extracted3();
20
21
//extracted4(startsWithNumber.test("1he"));
22
+ extracted5 ();
23
+ }
21
24
25
+ private static void extracted5 () {
26
+ Supplier <Apple > appleSupplier = Apple ::new ;
27
+ System .out .println (appleSupplier .get ());
28
+ Function <Integer ,Apple > appleFunction = Apple ::new ;
29
+ System .out .println (appleFunction .apply (10 ));
30
+ BiFunction <Integer ,String ,Apple > appleBiFunction = (i ,c )->new Apple (i ,c );
31
+ System .out .println (appleBiFunction .apply (10 ,Colors .RED ));
32
+ List <Integer > weights = Arrays .asList (7 , 3 , 4 , 10 );
33
+ map (weights , Apple ::new ).forEach (System .out ::println );
34
+ }
35
+ static public List <Apple > map (List <Integer > list , Function <Integer , Apple > f ) {
36
+ List <Apple > result = new ArrayList <>();
37
+ for (Integer i : list ) {
38
+ result .add (f .apply (i ));
39
+ }
40
+ return result ;
22
41
}
23
42
24
43
private static void extracted4 (boolean test ) {
@@ -28,9 +47,7 @@ private static void extracted4(boolean test) {
28
47
static Predicate <String > startsWithNumber = (String string ) -> Test .startsWithNumber (string );
29
48
30
49
static private Boolean startsWithNumber (String value ) {
31
- if (value .contains ("1" ))
32
- return true ;
33
- return false ;
50
+ return value .contains ("1" );
34
51
}
35
52
36
53
private static void extracted3 () {
0 commit comments