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.