Skip to content

Commit 241008e

Browse files
committed
Add Class to test Function java class.
This commit is for create a quick example for Function and Predicate.
1 parent 6c07d8c commit 241008e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package quick.platzi;
2+
3+
import java.util.function.Function;
4+
import java.util.function.Predicate;
5+
6+
public class MathFunctions {
7+
8+
public static void main(String[] args) {
9+
Function<Integer,Integer> square = x -> x * x;
10+
System.out.println(square.apply(5));
11+
12+
Persona persona = new Persona("Froy",'M',23);
13+
System.out.println(persona.isHombreAndMayorDeEdad());
14+
}
15+
16+
static class Persona {
17+
18+
private String nombre;
19+
private char sexo;
20+
private int edad;
21+
private Predicate<Persona> isHombreAndMayorDeEdad;
22+
23+
public Persona(String nombre,char sexo,int edad){
24+
this.nombre = nombre;
25+
this.sexo = sexo;
26+
this.edad = edad;
27+
isHombreAndMayorDeEdad = persona -> persona.sexo == 'M' && persona.edad >= 18;
28+
}
29+
30+
public boolean isHombreAndMayorDeEdad() {
31+
return isHombreAndMayorDeEdad.test(this);
32+
}
33+
}
34+
35+
36+
}

0 commit comments

Comments
 (0)