博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
scala中命名参数函数_Scala中带有命名参数的函数
阅读量:2537 次
发布时间:2019-05-11

本文共 1641 字,大约阅读时间需要 5 分钟。

scala中命名参数函数

具有命名参数的函数 (Functions with named arguments )

A function is Scala can take multiple arguments. These arguments are traditionally called in sequence while calling a function. But in Scala programming, the program is given the power to alter the traditional sequence of arguments. Scala provides its users named arguments these are used to change the order of using arguments at call.

一个函数是Scala可以接受多个参数。 这些参数通常在调用函数时按顺序调用。 但是在Scala编程中,程序有权更改传统的参数顺序。 Scala为用户提供了命名参数,这些参数用于更改调用时使用参数的顺序。

Suppose a function that has two variables var1 and var2. If we want to initialize var2 first then the following syntax is used.

假设一个函数具有两个变量var1和var2 。 如果我们要首先初始化var2,则使用以下语法。

Syntax:

句法:

functionName ( var2 = value2, var2 = value1 );

Explanation:

说明:

This will pass the value2 to the second argument in the list. And value1 in the first argument in the list.

这会将value2传递给列表中的第二个参数。 并在列表中的第一个参数中使用value1。

Example:

例:

object Demo {
def sub( a:Int, b:Int ) = {
println("Substraction = " + (a-b) ); } def main(args: Array[String]) {
println("The fucntion is called using named function call") sub(b = 5, a = 7); } }

Output

输出量

The fucntion is called using named function callSubstraction = 2

Explanation:

说明:

This code displays how to use named arguments in Scala? The code initializes a function named sub(), it expects two arguments and substracts second from first. At function call, the arguments are filled using the names that initialize them in the order the programmer wants.

此代码显示如何在Scala中使用命名参数? 该代码初始化了一个名为sub()的函数,它需要两个参数并从第一个减去第二个。 在函数调用时,将使用按程序员想要的顺序对其进行初始化的名称来填充参数。

翻译自:

scala中命名参数函数

转载地址:http://drxzd.baihongyu.com/

你可能感兴趣的文章
linux 命令汇总(搜索、fdfs、常用命令),虚拟机dump文件
查看>>
Nginx 反向代理解决浏览器跨域问题
查看>>
为什么现在我最终推荐内存OLTP
查看>>
git error: failed to push some refs to...
查看>>
Markdown指南
查看>>
influxDB的安装和简单使用
查看>>
JPA框架学习
查看>>
JPA、JTA、XA相关索引
查看>>
机器分配
查看>>
php opcode缓存
查看>>
springcloud之Feign、ribbon设置超时时间和重试机制的总结
查看>>
Go 结构体
查看>>
LINQ巩固
查看>>
观看杨老师(杨旭)Asp.Net Core MVC入门教程记录
查看>>
优化后的二次测试Miller_Rabin素性测试算法
查看>>
内部类。
查看>>
我的大学生活-4-21-吕家尧
查看>>
5、手把手教React Native实战之盒子模型BoxApp
查看>>
18日站立会议
查看>>
UIDynamic(物理仿真)
查看>>