I want to find the average area of a few rectangles using aggregate operations in Java 8.
Rectangle[] rects = new Rectangle[]{
new Rectangle(5, 10, 20, 30),
new Rectangle(10, 20, 30, 40),
new Rectangle(20, 30, 5, 15)
};
System.out.println("Average area: "
+ Arrays.asList(rects)
.parallelStream()
.map((RectangularShape r) -> (r.getWidth() * r.getHeight()))
.collect(Collectors.averagingDouble(o -> o)));
// I don't like this "o -> o"
System.out.println("Expected: 625");
However, I find the o -> o required by averagingDouble kind of silly. Is there a more intuitive replacement for this lambda (maybe even a stock identity lambda somewhere)?
o -> ois not exactly the identity here -- it is an unboxing function, actually equivalent toDouble::doubleValue.