0

I have a method with signature printStudents(List<Student> roster, CheckStudent) and a functional interface

interface CheckStudent {
    boolean test(Student s);
}


I have the following method invocation,

printStudents(
    roster,
    (Student s) -> s.getGender() == Student.Sex.MALE
        && s.getAge() >= 18
        && s.getAge() <= 25
);

Can we say that the functional interface is implemented? because from my experience we call an interface is implemented when a class implements it, however in this case there is no class implementing it?

My second question,interfaces define functionality and concrete classes implement the functionality, so in the above case is a class implicitly implementing it or not?

The Scientific Method
  • 2,374
  • 2
  • 14
  • 25
  • Add `@FunctionalInterface` annotation to the `CheckStudent` interface and this is it. – Victor Gubin Oct 17 '18 at 14:43
  • 1
    *because from my experience we call an interface is implemented when a class extends it, however is this case there is no class extending it?* -- I hope you mean implements. – Nicholas K Oct 17 '18 at 14:44
  • 1
    **"implements"** or not here is just a question of semantics. The fact is that your lambda expression is an instance of `CheckStudent`. Also, please use the built-in `Predicate` interface instead of writing your own. – ernest_k Oct 17 '18 at 14:45
  • @NicholasK right i mean *implements* – The Scientific Method Oct 17 '18 at 14:58

0 Answers0