当前位置:网站首页>On the closure function of Scala
On the closure function of Scala
2022-06-22 16:57:00 【ZH519080】
object Closure {
/**scala Closure is a function : A variable inside a function is not when it acts on , It can still be accessed from outside .
* The process of defining a closure function is to capture the free variables outside the function and form a closed function .
* When a variable outside a function changes ,scala The closure of can capture the change of variables ,
* scala Closures capture the variable itself, not its value */
// Application of closure function , Dependent on variables y, Reference to function closure01 Variables defined outside y
def closure01(x: Double) = (y: Int) => x*y
// And closure01 The function is the same ,closure02 The return value of depends on external variables y. Reference to function closure02 Variables defined outside y
var y = 2
def closure02(x: Int) = x*y
def main(args: Array[String]): Unit = {
val closureValue: Int => Double = closure01(3.5)
println(closure02(4))
println(closureValue(3))
}
}
边栏推荐
- Scala for derivation: the ability to define a value in the first part of a for expression and use it in subsequent (outer) expressions
- 交互电子白板有哪些特点?电子白板功能介绍
- spark与mysql:Did not find registered driver with class com.mysql.jdbc.Driver
- 【C语言】库函数qsort的使用
- 联合主键引发的思考
- How to open an account in flush? Is it safe to open an account online?
- 同花顺怎么开户?网上开户安全么?
- jsp学习之(二)---------jsp脚本元素和指令
- 洞见科技牵头的全球「首个」IEEE隐私计算「互联互通」国际标准正式启动
- The world's "first" IEEE privacy computing "connectivity" international standard led by insight technology was officially launched
猜你喜欢

Parts beyond the text are indicated by ellipsis

Vhedt business development framework
![[C language] use of library function qsort](/img/b0/6e86e31243164479b0f3d960d039ef.png)
[C language] use of library function qsort

新手必会的静态站点生成器——Gridsome

jMeter使用案例

华为云招募工业智能领域合作伙伴,强力扶持+商业变现

The world's "first" IEEE privacy computing "connectivity" international standard led by insight technology was officially launched
![[Alibaba cloud server - install MySQL version 5.6 and reinstall]](/img/5a/50b1de5f58235f6d11f6ad1eecc455.png)
[Alibaba cloud server - install MySQL version 5.6 and reinstall]

系统吞吐量、TPS(QPS)、用户并发量、性能测试概念和公式

视频会议时听不到声音该如何处理?
随机推荐
Vhedt business development framework
Implementation classes with similar execution logic use the template pattern
Spark on data skew
What is the difference between "img" and "ALT" in the interview question
In the era of video explosion, who is supporting the high-speed operation of video ecological network?
Interview knowledge points
Basic application of scala for
面对默认导入失败的情况
面试题之 <img>标签 的 title 和 alt 有什么区别
uniapp微信小程序获取页面二维码(带有参数)
scala-for的基本应用
Purchase guide - how to purchase a high-quality conference tablet, these aspects must be compared
面试知识点
为数字添加千分位符号(金额千分位)
Test for API
让代码优雅起来(学会调试+代码风格)
Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization
Parts beyond the text are indicated by ellipsis
面试题之JS判断数据类型的方法
Uniapp wechat applet obtains page QR code (with parameters)