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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

scala中何时使用下划线_在Scala中使用下划线

發布時間:2023/12/1 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scala中何时使用下划线_在Scala中使用下划线 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

scala中何時使用下劃線

Underscore (_) character is reserved in Scala and has multiple usages in the programming language. Based on functions that use the underscore have the following usages:

下劃線(_)字符在Scala中保留,并且在編程語言中有多種用法。 基于使用下劃線的函數具有以下用法 :

1) Existential Types

1)存在類型

These types are the ways of abstracting over data types,

這些類型是抽象數據類型的方法,

def functn(l: List[Option[_]]) = {}

2) Higher kind type parameters

2)更高種類的參數

A higher kind type is a constructor that contains a type constructor itself. Sample,

更高類型的類型是一個包含類型構造函數本身的構造函數。 樣品,

class incl [u[ _ ]]

3) Ignored variables

3)忽略變量

The ignored variables are declared using _. For example,

被忽略的變量使用_聲明。 例如,

val _ = 67

4) Ignored names of self-types

4)忽略自我類型的名稱

Merging two traits without extending each other is self type. Instead of names of self types, programmers can use the ignored names.?Sample,

融合兩個特質而不互相延伸是自我類型。 程序員可以使用忽略的名稱代替自身類型的名稱。 樣品,

trait incl { _: seq[_] => }

5) Wildcard patterns

5)通配符模式

In pattern matching, a wildcard pattern is used to match the unmatched case. Sample,

在模式匹配中,通配符模式用于匹配不匹配的大小寫。 樣品,

case (_) : //code

6) Wildcard imports

6)通配符導入

To import all classes of a package, the wildcard import is used. Sample,

要導入包的所有類,請使用通配符導入。 樣品,

import java.util._

7) Joining operators to letter

7)加入運營商來信

Sample,

樣品,

def fn_! (x : float) = 5

8) Assignment operator

8)賦值運算符

An assignment operator is an operator that assigns a value to the given variable/method. For example,

賦值運算符是將值分配給給定變量/方法的運算符。 例如,

def include_ = { ... }

9) Placeholder syntax

9)占位符語法

A placeholder is an anonymous function. Sample,

占位符是一個匿名函數。 樣品,

list (a, b, c) map(_+c)

10) Method values

10)方法值

If a method returns a single value and program directly uses it, then _ can be used instead of its name. For example, iterating over a list,

如果方法返回單個值并且程序直接使用它,則可以使用_代替其名稱。 例如,遍歷列表,

list (a, b, c) foreach println _

11) Default initializers

11)默認初始化

The initialization of variables without using values is done using underscore _. For example,

不使用值的變量初始化使用下劃線_完成。 例如,

var a : Int = _ // value is 0 i.e. default value.

12) Hiding imports

12)隱藏進口

You can hide imports of scala methods is done using the wildcard _.

您可以使用通配符_來隱藏scala方法的導入。

import java.util.{ArrayList => _, _}

翻譯自: https://www.includehelp.com/scala/use-of-underscore-in-scala.aspx

scala中何時使用下劃線

總結

以上是生活随笔為你收集整理的scala中何时使用下划线_在Scala中使用下划线的全部內容,希望文章能夠幫你解決所遇到的問題。

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