Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Some Questions Pertaining to Content in the OCP Java SE 11 Developer Complete Study Guide

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic