Java Functional Interfaces: java.util.function and When to Write Your Own | Effective Java L44
The Modern SDE
0:00 / 0:00
Java Functional Interfaces: java.util.function and When to Write Your Own | Effective Java L44
0 просмотров · 2 дн. назад
The Modern SDE
1,49 тыс. подписчиков
0 просмотров · 2 дн. назад
Lecture 44 of the Effective Java Masterclass by Engineer X · Part 6: Lambdas and Streams.
In this lecture
• A real boxing bug: UnaryOperator‹Integer› results compared with == fail above the Integer cache; IntUnaryOperator doesn't
• Lambdas change API design: take a policy as a function object instead of a Template Method subclass hook
• Choosing the parameter type: a hook that needs its owner and an argument is a BiPredicate, not a custom interface
• The six basic interfaces and how the other 37 follow (primitive versions, primitive results, two-argument forms, BooleanSupplier)
• When to write your own: no fit (three arguments, checked exceptions), or a name, a contract and default methods like Comparator
• Always @FunctionalInterface, and the compile error when a second abstract method sneaks in
• Don't overload methods on different functional interfaces: the ambiguity and the cast it forces
• Modern Java: still exactly 43 interfaces on Java 21, counted by a program
Chapters
0:00 The fee that broke equality
1:14 Lambdas change API design
2:40 Forty-three interfaces, six to remember
3:48 When to write your own
5:10 Always @FunctionalInterface
5:44 Overloads that need a cast
6:34 Modern Java: still 43
7:10 In the interview
7:49 Recap and quiz
Follows the topics of Effective Java, 3rd edition, by Joshua Bloch (Item 44: Favor the use of standard functional interfaces). Every explanation, example and line of code in this lecture is original.
Previous lecture: L043 Java Method References: Five Kinds, Two Receiver Traps, and When a Lambda Wins
Next lecture: L045 Java Streams vs Loops: When Streams Help and When a Plain Loop Wins
#Java #EffectiveJava #JavaInterview #SeniorJavaDeveloper #JavaBestPractices #EngineerX #JavaFunctionalInterfaces #JavaLambdas #JavaAPIDesign