当前位置:网站首页>Scala language learning-06-differences between name passing parameters, value passing parameters and function passing parameters
Scala language learning-06-differences between name passing parameters, value passing parameters and function passing parameters
2022-06-22 15:45:00 【Sunshine clover lxgzxj】
One 、 Test environment
| name | edition |
|---|---|
| operating system | win10 |
| CPU | 12th Gen Intel Core i7-12700H |
| Memory | 16G |
| JDK | 1.8.0_171 |
| Scala | 3.1.2 |
Two 、 Code
object TestParameterPassing {
def main(args: Array[String]): Unit = {
ValPmtPassing(ExampleFuc(100))
NamePmtPassing(ExampleFuc(100))
FuncPmtPassing(ExampleFuc,100)
}
def ExampleFuc(Num: Int): Int = {
println(" Call the example function once ")
Num
}
// Pass value parameter test function
def ValPmtPassing(Num: Int): Unit = {
printf(" Pass value parameter function test :%d\n",Num)
printf(" Pass value parameter function test :%d\n",Num)
println("+++++++++++++++++++++")
}
// Pass name parameter test function
def NamePmtPassing(Func: => Int): Unit = {
printf(" Passing parameter function test :%d\n",Func)
printf(" Passing parameter function test :%d\n",Func)
println("+++++++++++++++++++++")
}
// Pass function parameters to test functions
def FuncPmtPassing(Func: Int => Int, Num: Int): Unit = {
printf(" Pass function parameter function test :%d\n",Func(Num))
printf(" Pass function parameter function test :%d\n",Func(Num))
println("+++++++++++++++++++++")
}
}
3、 ... and 、 Running results
Call the example function once
Pass value parameter function test :100
Pass value parameter function test :100
+++++++++++++++++++++
Call the example function once
Passing parameter function test :100
Call the example function once
Passing parameter function test :100
+++++++++++++++++++++
Call the example function once
Pass function parameter function test :100
Call the example function once
Pass function parameter function test :100
+++++++++++++++++++++
Four 、 Personal understanding
1、 Named parameter :
The name passing parameter will bring the whole function body of the incoming function into , We are in function ValPmtPassing Call two times , So he will call it completely twice ExampleFuc, Output twice : Call the example function once .
2、 Pass value parameters :
The value passing parameter will only be called once at the beginning ExampleFuc, And then bring the return value of the incoming function into , So only output once : Call the example function once .
3、 Transfer function parameters :
The effect of the implementation is the same as that of the name passing parameter , But there is a slight difference in use , Only one incoming parameter is required for a named parameter , Just pass in the method name and the parameters required by the method , The function parameters need to be passed in multiple , In addition to the function name, there are parameters , Convenience upload name parameter is much better .
边栏推荐
- How to open an account in flush? Is online account opening safe?
- Hello, big guys. Error reporting when using MySQL CDC for the first time
- HMS core news industry solution: let technology add humanistic temperature
- "Forget to learn again" shell process control - 38. Introduction to while loop and until loop
- 向量2(友元及拷贝构造)
- 架构师之路,从「存储选型」起步
- New hybrid architecture iformer! Flexible migration of convolution and maximum pooling to transformer
- ROS2前置基础教程 | 小鱼教你用CMake依赖查找流程
- Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express
- Sdvo:ldso+ semantics, direct French Slam (RAL 2022)
猜你喜欢

The bank card identification function of Huawei machine learning service enables bank card identification and binding with one click

Charles 乱码问题解决

"Software defines the world, open source builds the future" 2022 open atom global open source summit will open at the end of July

Scala语言学习-05-递归和尾递归效率对比

On the routing tree of gin

The summary of high concurrency experience under the billion level traffic for many years is written in this book without reservation

全新混合架构iFormer!将卷积和最大池化灵活移植到Transformer

After 17 years, Liu Yifei became popular again: ordinary people don't want to be eliminated, but they also need to understand this

I rely on the sideline to buy a house in full one year: the industry you despise will make a lot of money in the next ten years!

C语言学习-17-函数作为参数传入函数
随机推荐
Charles 乱码问题解决
『忘了再学』Shell流程控制 — 38、while循环和until循环介绍
UK considers listing arm in London based on national security
Scala语言学习-06-传名参数、传值参数、传函数参数的区别
Reconstruction practice of complex C-end project of acquisition technology
Tdengine connector goes online Google Data Studio store
类似attention nlp
(pytorch advanced path 2) word embedding and position embedding
接了个私活项目,一下赚了15250,还有必要做主业吗?
求求了,别被洗脑了,这才是90%中国人的生存实况
高精度计算
关于 GIN 的路由树
Is the encryption market a "natural disaster" or a "man-made disaster" in the cold winter?
壹连科技冲刺深交所:年营收14亿 65%收入来自宁德时代
[Newman] postman generates beautiful test reports
Ultimate efficiency is the foundation for the cloud native database tdsql-c to settle down
社区文章|MOSN 构建 Subset 优化思路分享
Hello, big guys. Error reporting when using MySQL CDC for the first time
I took a private job and earned 15250. Is it still necessary to do my main business?
快速玩转CI/CD图形化编排