Blog

@FunctionalInterface interface MyInterface { Message send(String message); } class Message { public Message(String message) { System.out.println(message); } } class Test { public static void main(String[] args) { MyInterface myInterface = Message::new; myInterface.send(“Hello!”); } } Output: Hello! class Message { public Message(String message) { System.out.println(message); } public Message(String message1, String message2) { System.out.println(message1 + message2); }…

Read More Constructor Reference in Java

@FunctionalInterface interface Drawable { void draw(); } class Test { public void drawCircle() { System.out.println(“Drawing circle…”); } public static void main(String[] args) { Test test = new Test(); Drawable drawable = () -> test.drawCircle(); drawable.draw(); } } Output: Drawing circle… @FunctionalInterface interface Drawable { void draw(); } class Test { public void drawCircle() { System.out.println(“Drawing…

Read More Method Reference in Java

@FunctionalInterface public interface Supplier<T> { /** * Gets a result. * * @return a result */ T get(); } class Test { public static void main(String[] args) { Supplier<String> supplier = () -> “Java”; System.out.println(supplier.get()); } } Output: Java class User { private String name; private String username; private String membershipType; private String address; public…

Read More Supplier Functional Interface in Java

@FunctionalInterface public interface BinaryOperator<T> extends BiFunction<T,T,T> { /** * Returns a {@link BinaryOperator} which returns the lesser of two elements * according to the specified {@code Comparator}. * * @param <T> the type of the input arguments of the comparator * @param comparator a {@code Comparator} for comparing the two values * @return a {@code…

Read More BinaryOperator Functional Interface in Java

@FunctionalInterface public interface UnaryOperator<T> extends Function<T, T> { /** * Returns a unary operator that always returns its input argument. * * @param <T> the type of the input and output of the operator * @return a unary operator that always returns its input argument */ static <T> UnaryOperator<T> identity() { return t -> t;…

Read More UnaryOperator Functional Interface in Java

The Swift code example below demonstrates how to customize the UINavigationBar appearance via the AppDelegate.swift file. The blow Swift code example covers: Set UINavigationBar tint color, Set Navigation bar Title color, Set navigation bar ItemButton tint color, Set Navigation bar background image, Set navigation bar Back button tint color. import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate…

Read More Customize UINavigationBar Appearance Programmatically via AppDelegate

@FunctionalInterface public interface BiPredicate<T, U> { /** * Evaluates this predicate on the given arguments. * * @param t the first input argument * @param u the second input argument * @return {@code true} if the input arguments match the predicate, * otherwise {@code false} */ boolean test(T t, U u); /** * Returns a…

Read More BiPredicate Functional Interface in Java

@FunctionalInterface public interface Predicate<T> { /** * Evaluates this predicate on the given argument. * * @param t the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean test(T t); /** * Returns a composed predicate that represents a short-circuiting logical * AND of this…

Read More Predicate Functional Interface in Java

@FunctionalInterface public interface BiConsumer<T, U> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param u the second input argument */ void accept(T t, U u); /** * Returns a composed {@code BiConsumer} that performs, in sequence, this * operation followed by the {@code after}…

Read More BiConsumer Functional Interface in Java

@FunctionalInterface public interface Consumer<T> { /** * Performs this operation on the given argument. * * @param t the input argument */ void accept(T t); /** * Returns a composed {@code Consumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is…

Read More Consumer Functional Interface in Java

Java has evolved over the years to support functional programming, which is a programming paradigm that emphasizes writing code in terms of functions. In Java, functional programming is made possible with the help of functional interfaces, which are interfaces that define a single abstract method. Functional interfaces can be implemented using lambda expressions or method…

Read More Master functional interfaces in Java for efficient code