I will be much obliged if someone will assist me with providing answers to the following questions, please; the questions pertain to information provided in the OCP Java SE 11 Developer Complete Study Guide:
(1.) The following sentence is made on page 675, just before the section titled Implementing Function and BiFunction: “The method reference includes both the instance variable and parameter for startsWith().” Shouldn’t this sentence be as follows, instead: “The lambda includes both the instance variable and parameter for startsWith()”? I ask this question because it is the lambda, not the method reference, that has both the instance variable - i.e., the instance variable with identifier “string” - and the parameter for the method startsWith() - i.e., the lambda parameter with identifier “prefix.”
(2.) The following sentence is made in the last paragraph on page 676, just before the discussion in the section titled Creating Your Own Functional Interfaces: “For the method reference, the first parameter is the instance that the concat() is called on, and the second is passed to concat().” Since this sentence applies to the lambda, rather than the method reference, shouldn’t the sentence be as follows, instead: “For the lambda, the first parameter is the instance that the concat() is called on, and the second is passed to concat().”
(3.) Isn’t another correct answer, for the blank on the first line 8 on page 679, a BiFunction whose abstract method has two String parameter types and a Boolean (wrapper class) return type? Even though the lambda in this exercise has a boolean (primitive) return type, won’t this return type be autoboxed into an Integer object? That the answers to these foregoing two questions should be the affirmative is supported by the following explanations in the book itself:
(A) The answer given for the blank on the first line 6 on the same page; this answer implies that a boolean is autoboxed into a Boolean when it explains that either a Predicate or a Function may fill the blank in this exercise, even though the lambda returns a primitive boolean, not an Object (i.e., the Boolean wrapper class) type.
(B) The following sentences in the middle of page 676 in the book: “This function turns a String into an Integer. Well, technically it turns the String into an int, which is autoboxed into an Integer.”
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop