Java has a set of primitive-specialized functional interfaces of the form:
✅ XToYFunction
These are used to convert from one primitive (or boxed) type to another efficiently — avoiding boxing and unboxing.
Continue readingJava has a set of primitive-specialized functional interfaces of the form:
XToYFunctionThese are used to convert from one primitive (or boxed) type to another efficiently — avoiding boxing and unboxing.
Continue readingLet’s dive into BiPredicate<T, U>, a functional interface used to evaluate a boolean condition based on two inputs.
✅ BiPredicate<T, U>
@FunctionalInterface
public interface BiPredicate<T, U> {
boolean test(T t, U u);
}
Continue reading Excellent question! Let’s break down the BiFunction<T, U, R> functional interface — one of the most versatile tools in Java functional programming.
BiFunction<T, U, R>@FunctionalInterface
public interface BiFunction<T, U, R> {
R apply(T t, U u);
}
T and URFunction<T, R>Let’s talk about BiConsumer<T, U> — it’s part of the java.util.function package and is a functional interface used when you want to perform an action with two inputs and return nothing.
Supplier<T>Package: java.util.function
T, with no input.@FunctionalInterface
public interface Supplier<T> {
T get();
}
🧠 Example:
Supplier<String> greetingSupplier = () -> "Hello, world!";
System.out.println(greetingSupplier.get()); // Output: Hello, world!
Continue reading These are used when you accept a value and do something with it, but you don’t return a result.
Continue readingPredicate<T>Package: java.util.function
T and returns a boolean.@FunctionalInterface
public interface Predicate<T> {
boolean test(T t);
}
🧠 Example:
Predicate<String> isLongWord = str -> str.length() > 5;
System.out.println(isLongWord.test("hello")); // false
System.out.println(isLongWord.test("predicate")); // true
Continue reading A generic interface that operates on two operands of the same type and returns a result of the same type.
@FunctionalInterface
public interface BinaryOperator<T> extends BiFunction<T, T, T> {
// No additional methods
}
🧠 Example:
BinaryOperator<Integer> add = (a, b) -> a + b;
System.out.println(add.apply(5, 7)); // Output: 12
Continue reading They are all specialized versions of UnaryOperator<T> for Java primitives: double, int, and long.
Let’s dive into UnaryOperator<T>, which is a specialized version of Function<T, R> when input and output types are the same.