Sobes.tech
Junior — Middle

Can you explain what an anonymous function (lambda) is in Java?

sobes.tech AI

Answer from AI

An anonymous function (lambda) in Java is a function without a name that can be passed as an object. It is used for concise writing of functional interfaces, for example, in event handlers or when working with collections.

Example of a lambda expression in Java:

List<String> names = Arrays.asList("Anna", "Bob", "Charlie");
names.forEach(name -> System.out.println(name));

Here, name -> System.out.println(name) is an anonymous function that outputs each element of the list.

Can you explain what an anonymous function (lambda)… - sobes.tech