Lambdas in java it is just a syntax shugar for anonymous classes
Code from you example is equal to
List<person> people = new ArrayList<>();
people.add(new Person("Mohamed", 69));
people.add(new Person("Doaa", 25));
people.add(new Person("Malik", 6));
Predicate<person> pred = new Predicate<person>() {
public boolean test(person p) {
return p.getAge() > 65;
}
}
To simplify syntax in java you can skip type declaration in lambda expression and add only name of value, like you did.
Predicate<person> pred = (p) -> p.getAge() > 65;
Or if you want, you can write something like this
Predicate<person> pred = (person p) -> p.getAge() > 65;
Its to be noted you can skip type declaration only if it can be counted from lambda code somehow. For example
Comparator<String> comp
= (firstStr, secondStr) // Same as (String firstStr, String secondStr)
-> Integer.compare(firstStr.length(),secondStr.length());