In the Lambda Expressions Java Tutorial, approach 5 improves upon approach 4 by converting the anonymous class instantiation
new CheckPerson() {
public boolean test(Person p) {
return p.getGender() == Person.Sex.MALE
&& p.getAge() >= 18
&& p.getAge() <= 25;
}
}
to
(Person p) -> p.getGender() == Person.Sex.MALE
&& p.getAge() >= 18
&& p.getAge() <= 25
Is there an equivalent in Scala so that I can avoid doing:
new CheckPerson {
def test(p: Person): Boolean = {
p.getGender == Person.Sex.MALE
&& p.getAge >= 18
&& p.getAge <= 25
}
}