This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 39157
724
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: 39157
724
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!