Junior — Middle
What is the name of the call to the .map() method using a method reference to Object::toString in Java streams?
sobes.tech AI
Answer from AI
Calling the .map() method using a reference to the Object::toString method is called a method reference. It is a concise and more readable way to pass a method to a functional interface instead of using a lambda expression.
Example:
List<Integer> numbers = List.of(1, 2, 3);
List<String> strings = numbers.stream()
.map(Object::toString) // method reference
.collect(Collectors.toList());
Here, Object::toString is a method reference that is passed to .map() to convert each element to a string.