当前位置:网站首页>Copy ‘XXXX‘ to effectively final temp variable
Copy ‘XXXX‘ to effectively final temp variable
2022-07-01 21:42:00 【小曲同学呀】
今天,在项目中使用lambda表达式遇到了一个问题:
Copy 'standDatasMap' to effectively final temp variable
翻译过来就是:xxxx使用有效的最终变量。
那什么意思呢?
大家先看一下,lambda表达式的规则:
- 只能引用标记了 final 的外层局部变量,这就是说不能在 lambda 内部修改定义在域外的局部变量,否则会编译错误。
- 局部变量可以不用声明为 final,但是必须不可被后面的代码修改(即隐性的具有 final 的语义)
- 不允许声明一个与局部变量同名的参数或者局部变量。
给大家写个例子,简单情景再现下:
原因:
这是因为lambda表达式不接受动态传参。
修改如下:
我们可以加一个map,用来接收动态参数,即可解决此问题。
边栏推荐
- Manually implement function isinstanceof (child, parent)
- 使用闭包实现点击按钮切换 toggle
- Application of real estate management based on 3D GIS
- MQ learning notes
- TOPS,处理器运算能力单位、每秒钟可进行一万亿次
- 浏览器tab页之间的通信
- burpsuite简单抓包教程[通俗易懂]
- 企业架构与项目管理的关联和区别
- 指标陷阱:IT领导者易犯的七个KPI错误
- Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
猜你喜欢
【深度学习】利用深度学习监控女朋友的微信聊天?
Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc
AIDL基本使用
手动实现function isInstanceOf(child,Parent)
Getting started with the lockust series
Talking from mlperf: how to lead the next wave of AI accelerator
从MLPerf谈起:如何引领AI加速器的下一波浪潮
比较版本号[双指针截取自己想要的字串]
小 P 周刊 Vol.11
基于K-means的用户画像聚类模型
随机推荐
小 P 周刊 Vol.11
月入1W+的自媒体达人都会用到的运营工具
Simple interactive operation of electron learning (III)
Go - exe corresponding to related dependency
Difference and use between require and import
An operation tool used by we media professionals who earn 1w+ a month
MySQL清空表数据
灵动微 MM32 多路ADC-DMA配置
String type conversion BigDecimal, date type
函数基本学习之一
杰理之、产线装配环节【篇】
收到一封CTO来信,邀约面试机器学习工程师
Use of vscode
News classification based on LSTM model
Pytest Collection (2) - mode de fonctionnement pytest
TOPS,处理器运算能力单位、每秒钟可进行一万亿次
微信小程序,连续播放多段视频。合成一个视频的样子,自定义视频进度条
Training on the device with MIT | 256Kb memory
微软、哥伦比亚大学|GODEL:目标导向对话的大规模预训练
String类型转换BigDecimal、Date类型