Functional Interfaces, Lambdas and Method References
40 min · Intermediate
A functional interface is an interface with exactly one abstract method, and a lambda or method reference is a short way to supply that one method. Every stream, Optional and Comparator question rests on this idea. Section 8, Functional Interfaces in Practice and Method References in Depth, taught it; this lesson is the interview revision.
Topics in this lesson
- The core interfaces: Function, Predicate, Consumer, Supplier, BiFunction
- @FunctionalInterface rules
- Four kinds of method references
- Effectively final variables in lambdas
- Lambda vs anonymous class: this and scope
Interview questions this lesson answers
- What is a functional interface?
- What does the @FunctionalInterface annotation do? Is it required?
- Can a functional interface have default and static methods?
- Comparator declares both compare and equals. Why is it still functional?
- Name the main functional interfaces in java.util.function.
- What is the difference between Function and Consumer?
- What is the difference between Supplier and Callable?
- What is the difference between UnaryOperator and Function?
- Why are there primitive functional interfaces like IntPredicate?
- What is the difference between andThen and compose on Function?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.