Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 Map and Reduce doesnt run

I was using Project Lambdas' .map() method to extract some data from a List object. Before, Jdk 1.8 contained Mapper interface but now, I see that it map method gets Function interface. My method usage below:

 List<Nut> nutList =new ArrayList<Nut>();

I've added some items to nutList and im using below method to extract a fields value by getter.

nutList.stream().map(n->n.getShell())

But above n parameter behave like an Object and it doesn't access to original object's method. This usage was normally run with Mapper Functional interface.

like image 707
Rahman Usta Avatar asked Sep 04 '26 04:09

Rahman Usta


1 Answers

Under b75, the following code compiles and runs correctly:

    List<Nut> nutList =new ArrayList<>();
    nutList.stream().map(n -> n.getShell()).forEach(System.out::print);

Perhaps you're using an older version?

like image 74
Maurice Naftalin Avatar answered Sep 06 '26 16:09

Maurice Naftalin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!