On page 46, “Iterating a String” we find this text:
Since we already provided a target for the method, the Java compiler decided to use the parameter of the synthesized method as an argument to the referenced method, like so:
System.out.println(parameter);
. Sweet.
This in the context of
str.chars().forEach(System.out::println);
Let’s recall the meaning of “parameter” and “argument”:
- “parameter”: item appearing in a function’s or method’s definition
- “argument”: value passed to a function at runtime (“actual parameter”)
So maybe the text should be reformulated as follows:
Since we already provided a target for the method (namely
System.out
), the Java compiler uses the (integer) argument passed to the synthesized method (called inside theforEach()
loop) as argument passed to the referenced method, like so:System.out.println(argument);
. Sweet.
This may be a bit clearer.
However, there are more places later where the argument/parameter distinction may not be made or be confusing (that’s how I read it at least).
For example on page 48,
The method references here helped remove the mundane parameter routing.
It feels as if
The method references here helped remove the mundane argument routing.
would be more correct.