• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 90
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 90
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic