Error:
Error Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Jan 09 14:22:48 IST 2021 There was an unexpected error (type=Internal Server Error, status=500). Unresolved compilation problem: The method map(Function<? super Rating,? extends R>) in the type Stream is not applicable for the arguments (( rating) -> {}) java.lang.Error: Unresolved compilation problem: The method map(Function<? super Rating,? extends R>) in the type Stream is not applicable for the arguments (( rating) -> {}) at com.study.movie.controller.CatalogController.getCatalog(CatalogController.java:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at
Code:
return ratings.stream() .map(rating -> { Movie movie=restTemplate.getForObject("http://localhost:8081/movies/"+rating.getMovieId(), Movie.class); new CatalogItem(movie.getName(),movie.getDescription(),rating.getRating()); }) .collect(Collectors.toList());
Advertisement
Answer
The code block in your lambda expression doesn’t return anything, but the .map()
method requires a function / lambda that returns something.
You should write your code as
return ratings.stream() .map(rating -> { Movie movie=restTemplate.getForObject("http://localhost:8081/movies/"+rating.getMovieId(), Movie.class); return new CatalogItem(movie.getName(),movie.getDescription(),rating.getRating()); }) .collect(Collectors.toList());