• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

OCP-IZO-809: Chapter 2 Question 11

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading the book of Jeanne Boyarsky and Scott Selikoff. There is a question given in the exercise: which lambda expression can replace MySecret class :


Its given the following option as correct:



As variable e is already in use and cannot be redefined in lambda ,I dont think this option should be correct. Can you please suggest.
 
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please give us full details of the book, including authors and page number, and full details of the question, otherwise those of us who don't have that book can't help you.
 
Rancher
Posts: 3620
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the code indeed should cause compilation error as  lambda body declares the same name variable as parameter, for example:

 
Campbell Ritchie
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are probably correct about the compiler error, but you haven't given enough information that we can verify that by running the code.
 
Mikalai Zaikin
Rancher
Posts: 3620
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you posted some more context: even without re-declaring I see here a problem -- the e is assumed to be double primitive



It's similar to (pseudo code):


 
author & internet detective
Posts: 39997
807
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My copy of the book says A and F are correct.

F is caller(e) -> { String f= ""; return "Poof"; }

It looks like you quoted option e which is not the answer and:
F is caller(e) -> { String e = ""; return "Poof"; }
 
Saurabh Ag
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my version of book it says A,D,F where D should not be correct as its the option I have asked above.
 
Campbell Ritchie
Marshal
Posts: 69494
277
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you get two versions with different answers? Have you got a .pdf or paper book or what? Please quote the edition and impression numbers and copyright date, which should be on the page after the title page.
 
Jeanne Boyarsky
author & internet detective
Posts: 39997
807
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or Kindle? Or something else?
 
I don't like that guy. The tiny ad agrees with me.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic