日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

scala中命名参数函数_Scala中带有命名参数的函数

發布時間:2023/12/1 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scala中命名参数函数_Scala中带有命名参数的函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 call Substraction = 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()的函數,它需要兩個參數并從第一個減去第二個。 在函數調用時,將使用按程序員想要的順序對其進行初始化的名稱來填充參數。

翻譯自: https://www.includehelp.com/scala/functions-with-named-arguments-in-scala.aspx

scala中命名參數函數

總結

以上是生活随笔為你收集整理的scala中命名参数函数_Scala中带有命名参数的函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。