Java 8 Functional interface method name not required

Since the example you give here is actually a Consumer, it can be applied to a stream of data (a String Consumer in your example) to perform a given action on each of the elements of the stream.
In this case you don’t need to be explicit about the method name; like:

List<String> strList = ...;
strList.stream().forEach((str) -> System.out.println(str));

where

(str) -> System.out.println(str)

is your String Consumer

But this is only because the use of the functional interface’s method is hidden in the “forEach” definition.

I suppose this may be what you meant by “method name not required”.

Leave a Comment