Junior — Middle
What is your experience in developing interfaces based on functions or functions as the main component?
sobes.tech AI
Answer from AI
In Java, interfaces with default methods and functional interfaces allow functions to be used as objects. For example, the Function<T, R> interface from the java.util.function package enables creating functions that can be passed around and combined.
Example of using a functional interface:
import java.util.function.Function;
public class Example {
public static void main(String[] args) {
Function<Integer, Integer> square = x -> x * x;
System.out.println(square.apply(5)); // Outputs 25
}
}
This approach simplifies development, makes the code more expressive, and supports functional programming style.