• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Chapter 2, question 11 in OCP 8 Programmer II Study Guide (pages 98 and 551)  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the answer to above review question, the solutions say A, D, F are correct. Why is D correct? It has a lambda expression as in



which isn't valid Java 8, as it tries to declare e both as a parameter and a local variable otherwise in the same lambda. Thanks for any help.

Apologies if this has already been discussed. I wasn't able to find this issue here or in the errata.

I see this in both the online test bank and the Kindle book (ISBN: 978-1-119-06790-0).
 
author & internet detective
Posts: 39234
727
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Benjamin,
Welcome to CodeRanch!

That's odd. The printed book says A and F are correct. (D is clearly wrong). Can you look at the answer text. Mine has this as the second stence "C, D and E are incorrect because the variable e is already in use from the lambda and cannot be redefined."

Granted that's not all that's wrong with it, but it is enough to rule out the answer choice.
 
Benjamin Fischer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for confirming, Jeanne! It seems I'm looking at an outdated version then. The online test and my Kindle book say


A, D, F. B is incorrect because it does not use the return keyword. C and E are incorrect because the variable e is already in use from the lambda and cannot be redefined. Additionally, C is missing the return keyword and E is missing the semicolon. A, D, and F are the only correct lambda expressions that match the functional interface.



I bought the Kindle book this year on January 6, 2019 via www.amazon.co.uk, so it should be a recent version. Anyway, thanks for the help.
 
Jeanne Boyarsky
author & internet detective
Posts: 39234
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Benjamin Fischer wrote:I bought the Kindle book this year on January 6, 2019 via www.amazon.co.uk, so it should be a recent version. Anyway, thanks for the help.


I don't think they update the Kindle book. What's odd is that it was *never* a problem in the print book.
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!