Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.1886 :

Posted: Wed Aug 14, 2019 10:13 pm
by dongyingname

Code: Select all

class Book {
   double price;
   String title;
   public double getPrice(){....}
   //constructors and setters
}
using thrid option in main with .toDouble() removed.

Code: Select all

double d = books.stream().flatMap(bs -> bs.stream()).map(book -> book.getPrice()).sum();
It doesn't compile, and the error

Code: Select all

cannot find symbol
  symbol:   method sum()
  location: interface Stream<Double>
points to .sum()
I knew that autoboxing was expensive in stream, but I need help explain why this happens.

Re: About Question enthuware.ocpjp.ii.v11.2.1886 :

Posted: Wed Aug 14, 2019 10:38 pm
by admin
Well, does Stream have sum() method?