How do java – lambda expressions work with predicate?

I need more explanation about lambda expressions‘ How does' p 'mean list < person >? Can you explain clearly?

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 = (p) -> p.getAge() > 65;

Solution

No, P not a list < person > but a person

Predicate<Person> pred = p -> p.getAge() > 65;

This lambda expression declares a formal parameter and returns a Boolean value Therefore, it can be expressed as predicate (because the predicate interface has a single functional method with this exact signature, called test) The type of P will be determined by the type of predicate you are creating

For example, in the following code, P will be list < person >:

Predicate<List<Person>> predicate = p -> p.isEmpty();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>