java - 我的流图中的错误是什么意思?
问题描述
错误:
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
代码:
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());
解决方案
lambda 表达式中的代码块不返回任何内容,但是.map()
方法需要一个返回某些内容的函数/lambda。
您应该将代码编写为
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());
推荐阅读
- c++ - macosx 上信号处理程序中的 rip 寄存器值
- python - shap.KernelExplainer,为背景中有许多零的图像更改“mask_image”函数
- c - 我可以发布使用补丁的 crate 吗?
- python - 在 Pandas 中使用 lambda 和 .apply()
- python - Python 键盘状态
- javascript - 使用 Express 构建 API 时出现意外的文件传输行为
- java - 为存储库创建自定义过滤器的最佳方法是什么?
- python - 如何在黑色空间内使用滚动条调整此框架?
- java - 如何捕获视频帧 Exoplayer android
- stm32 - 如何找到连接信号的模拟电压周期和平均值?