Lesson content
Read, practise, then check your understanding
A functional interface has one abstract method; @FunctionalInterface asks the compiler to enforce that shape. Object methods and defaults do not count against it.
Standard vocabulary
Predicate<String> present = text -> text != null;
Predicate<String> useful = present.and(text -> !text.isBlank());
Function<String, Integer> length = String::length;
Supplier<Instant> clock = Instant::now;
Consumer<String> output = System.out::println;
Use primitive specializations such as IntFunction to avoid boxing in hot paths. UnaryOperator and BinaryOperator preserve a type. Prefer standard interfaces for interoperability; create a domain-specific one when its name, checked-exception contract, or extra semantics materially clarify the API.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.