Junior — Middle
Can you explain what is meant by the term 'lambda' in programming?
sobes.tech AI
Answer from AI
In programming, a lambda usually refers to an anonymous function — a function without a name, which can be defined directly at the point of use. In Java, lambda expressions appeared in version 8 and allow writing concise code for functional interfaces.
Example of a lambda expression in Java:
// Interface with one method
interface MathOperation {
int operation(int a, int b);
}
// Using a lambda
MathOperation addition = (a, b) -> a + b;
int result = addition.operation(5, 3); // result = 8
Lambdas simplify working with collections, allow writing more readable and concise code, especially when using Stream API.