Primitive Functional Interfaces:Skip the Box on the Hot Path
Use java.util.function’s primitive SAM grid to skip boxing on hot numeric paths, fill IntStream slots, and leave ToIntFunction out of ordinary application code.
Read More8 post(s)
Use java.util.function’s primitive SAM grid to skip boxing on hot numeric paths, fill IntStream slots, and leave ToIntFunction out of ordinary application code.
Read MoreUse BiFunction, BiPredicate, and BiConsumer for two-argument slots — apply, test, accept — and fill Map.merge, compute, and forEach without inventing a pair type.
Read MoreUse UnaryOperator and BinaryOperator when input and output are the same type — List.replaceAll, Stream.reduce, Collectors.reducing, and minBy / maxBy.
Read MoreUse Java’s Supplier<T> for lazy values — get, orElseGet, factories, supplyAsync — so you do not build work until something actually needs the result.
Read MoreUse Java’s Consumer<T> for side effects — accept, andThen — and see where Stream.forEach, Optional.ifPresent, and peek already ask for it.
Read MoreUse Java’s Predicate<T> to test values — test, and, or, negate, isEqual, Predicate.not (Java 11) — and see where Stream.filter, anyMatch, and removeIf already ask for it.
Read MoreUse Java’s Function<T,R> to map values — apply, compose, andThen, identity — and see where Stream.map, Optional.map, and Collectors already ask for it.
Read MoreWhat a Java functional interface is, the four shapes in java.util.function, when to write your own SAM type, and a living map of every post in this series.
Read More