Java 8 Map and Reduce not starting

I used the Project Lambdas.map () method to retrieve some data from the List object. Previously Jdk 1.8 contained the Mapper interface, but now I can see that the map method gets a functional interface. Using my method below:

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

      

I added some items to nutList and im using the method below to retrieve the field value using a getter.

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

      

But above n, the parameter behaves like an object and does not have access to the original method of the object. This usage was usually done using the functional interface Mapper.

+3


source to share


1 answer


In section b75, the following code compiles and runs correctly:

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

      



Are you using an older version perhaps?

+1


source







All Articles