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中何时使用下划线

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377396.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何利用C#编写网页投票器程序 如何使用代理来投票 代理IP来投票

一、前言看个图,了解下投票的过程。提交投票信息投票页 ――――――――>投票信息处理页反馈投票结果(请求页)<―――――――(响应页)一般情况下,填写投票信息,然后点提交按钮发送到响应页,这…

【设计模式之美】<Reading Notes>贫血模型与充血模型

小知识 需要了解的一些名词 1、领域驱动设计(Domain Driven Design,简称 DDD) 2、MVC 三层架构 : M 表示 Model,V 表示 View,C 表示 Controller。 它将整个项目分为三层:展示层、逻辑层、数据层…

TAFE的完整形式是什么?

TAFE:拖拉机和农用设备 (TAFE: Tractors and Farm Equipment) TAFE is an abbreviation of Tractors and Farm Equipment Limited. It is an Indian tractor manufacturer which is founded at Chennai in 1960. It is the second-largest tractor manufacturer in …

Oracle 10g 数据库的备份和还原

一、备份数据库1.在图形工具中,如sqldeveloper,pl/sqldeveloper用以下这句查找空表select alter table ||table_name|| allocate extent; from user_tables where num_rows0;2.把第一步执行得到的结果当用sql语来再次执行3.到oracle服务器上执行备份语句. 运行-cmd …

用户行为分析指导电商精细化运营

规模和利润,这两个在商业运营中最基本的指标,却在电子商务市场中遭遇了不同的待遇。前两年,几乎所有的电商企业都只追求规模,不追求利润,导 致自身的运营极其粗放,绝大多数电商公司只有两招:猛打…

【C++基础】 类模板

类模板 模板是将类中某些类型变为泛型,从而定义一个模板。 如下: 类模板的语法 直接进行对比: 泛型化之前 泛型化之后类模板的实例化 注意:只要是对类模版进行实例化,编译器就会生成一个类!&#xff0…

ruby 怎么抛异常_Ruby中的异常处理

ruby 怎么抛异常Ruby异常处理 (Ruby Exception Handling) Exceptions are abnormal conditions arising in the code segment at runtime in the form of objects. There are certain predefined Exception classes whereas we can create our exception known as Custom excep…

cocos2d-x游戏开发系列教程-中国象棋02-main函数和欢迎页面

之前两个博客讲述了象棋的规格和工程文件之后,我们继续深入的从代码开始学习cocos2dx首先从程序入口main函数开始main函数int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow) {UNREFERENCED_PARAMETER(h…

[原创]Android中的android:layout_width和android:width的区别

在android系统中&#xff0c;我们可以通过在xml资源文件中定义布局&#xff0c;一般的写法是&#xff1a; <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"ma…

【C++基础】模板参数与模板继承

模板参数 默认类型参数 函数参数可以设定一个默认值&#xff0c;我们现在可以对类模板的类型参数设定一个默认类型。 指定泛型Stack的默认类型参数为 int template<typename T int> class Stack{... };当我们这样定义一个对象时&#xff1a; Stack<> stack;使…

UNIX标准化及实现之POSIX标准可选头文件

POSIX标准定义的可选头文件 头文件说明<aio.h>异步I/O<mqueue.h>消息队列<pthread.h>线程<sched.h>执行调度<semaphore.h>信号量<spawn.h>实时spawn接口<stropts.h>XSI STREAMS接口<trace.h>事件跟踪转载于:https://www.cnblo…

Julia中的denominator()函数

Julia| 分母()函数 (Julia | denominator() function) denominator() function is a library function in Julia programming language, it is used to get the denominator of the rational representation of the given value. denominator()函数是Julia编程语言中的库函数&a…

【C++基础】STL迭代器

已知&#xff1a; STL组成部分&#xff1a; 容器、迭代器、算法、函数对象、空间分配器 容器&#xff1a;用于保存一组数据&#xff0c;数据个体被称为元素 迭代器&#xff1a;用于遍历容器中的元素&#xff0c;容器都有自己专属的迭代器&#xff0c;只有容器才知道如何遍历自己…

用ie9浏览器若出现看视频有声音没图像的问题处理

当我们在用ie9浏览器上网想看视频时&#xff0c;有时会遇到各种问题&#xff0c;尤其是有关声音和图像的。有时候有声音没图像&#xff0c;但有时候有图像却没声音。各种问题。当遇到某些问题时&#xff0c;只要是关于网页视频的&#xff0c;一般都会选择更新网页视频播放插件&…

java架构师之路:JAVA程序员必看的15本书的电子版下载地址

java架构师之路&#xff1a;JAVA程序员必看的15本书的电子版下载地址 作为Java程序员来说&#xff0c;最痛苦的事情莫过于可以选择的范围太广&#xff0c;可以读的书太多&#xff0c;往往容易无所适从。我想就我自己读过的技术书籍中挑选出来一些&#xff0c;按照学习的先后顺序…

office数据集dslr_DSLR的完整形式是什么?

office数据集dslrDSLR&#xff1a;数码单镜反光 (DSLR: Digital Single-Lens Reflex) DSLR is an abbreviation of digital single-lens reflex. It alludes to a digital camera which with the sensor of digital imaging merges optics and mechanism of single-lens reflex…

envs\TensorFlow2.0\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning 解决方案

import tensorflow后的完整报错&#xff1a; D:\Anaconda3\envs\TensorFlow2.0\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or ‘1type’ as a synonym of type is deprecated; in a future version of numpy, it will b…

转义序列

转义序列描述\n换行符\r回车\t水平制表符\\反斜杠\$美元符\"双引号\[0-7]{1.3}八进制记法\x[0-9A-Fa-f]{1,2}十六进制记法转载于:https://www.cnblogs.com/cindylu520/archive/2012/07/05/2577246.html

Java动态代理模拟spring的AOP

广州疯狂软件学院拥有三大课程体系包括&#xff1a;java课程&#xff0c;android课程&#xff0c;ios课程&#xff0c;疯狂软件年终钜惠&#xff0c;报名java就业班&#xff0c;免费赠送基础班&#xff0c;名额有限&#xff0c;本月火热报名中&#xff0c;欢迎有志之士电话或者…

xlrd.biffh.XLRDError: Excel xlsx file; not supported解决方法

将原本的xlrd卸载&#xff0c;安装旧版本&#xff1a; pip uninstall xlrd pip install xlrd1.2.0转自&#xff1a;https://www.cnblogs.com/xiaoqiangink/p/14144517.html