Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Question/Errata for OCP:Oracle Certified Professional Java SE 8 Programmer II Study Guide - page 557  RSS feed

 
Ranch Hand
Posts: 44
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

For the answer to question 14 on page 557, I was wondering if the second "autoboxing" shouldn't be understood as "unboxing" since we are converting to a primitive like explained?

Thanks for your answer.

Kind regards,
Guillaume
 
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guillaume,
You are correct and I logged it. This is a case of "sloppy" English.

Autoboxing does mean primitive to object and unboxing means object to primitive. Sometimes people (incorrectly) use autoboxing to refer to both ways. I mention this because you could easily encounter this "sloppy English" problem in other books or even when talking to people in the workplace. Which means it is good to be suspicious when you hear "autoboxing" and consider it might be meant either way.
 
Guillaume Bailly
Ranch Hand
Posts: 44
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation. I will pay attention in the future, now even more :-)
 
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The explanation says: Converting from a double to an int would require a cast inside the lambda, but
7: Stream<Integer> s2 = ds.mapToInt(x -> (int)x); still doesn't work. mapToInt has to be replaced by mapToObject.
Furthermore line 6 throws an IllegalStateException: stream has already been operated upon


 
Jeanne Boyarsky
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Juerg Bauman wrote:The explanation says: Converting from a double to an int would require a cast inside the lambda, but
7: Stream<Integer> s2 = ds.mapToInt(x -> (int)x); still doesn't work. mapToInt has to be replaced by mapToObject.


Actually mapToObj. And yes, I've added that to the errata. A cast isn't needed in any event.

Juerg Bauman wrote:Furthermore line 6 throws an IllegalStateException: stream has already been operated upon


While that's true, the question and explanation are about compiling. The runtime exception is a "decoy" answer to try to trick you.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!