Create a Java program to demonstrate the use of an interface for custom function
import java.util.function.Function; @FunctionalInterface interface CustomFunction<T, R> { R apply(T t); } public class Main { public static void main(String[] args) { Function<Integer, String> toString = Object::toString; CustomFunction<Integer, String> customToString = Object::toString; String result1 = toString.apply(42); String result2 = customToString.apply(42); System.out.println("Result using Function : " + result1); System.out.println("Result using CustomFunction : " + result2); } }
Result using Function : 42 Result using CustomFunction : 42
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions