Scala - 什么是 ' =>SomeType' 是什么意思? [英] Scala - What does ' => SomeType' means?

查看:43
本文介绍了Scala - 什么是 ' =>SomeType' 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天想请教一下=>SomeType 的意思.我发现它在 这篇文章 中使用过.它在顺序组合器"部分.

Today I would like to ask what does the => SomeType mean. I found it used in this article. It's in the part 'The Sequential Combinator'.

感谢您的回答!

推荐答案

意思是可以运行的代码块.

It means a block of code that you can run.

例如:

scala> def doTwice(op: =>Unit) = {op; op}
doTwice: (op: => Unit)Unit

scala> doTwice({println("Hi")})
Hi
Hi

在这种情况下,=>Unit{println("Hi")}

这里的SomeType"是 Unit,因为 println 不产生值.如果它产生一个 Int,它将是 =>Int.

Here "SomeType" is Unit because println doesn't produce a value. If it produced an Int, it would be =>Int.

这篇关于Scala - 什么是 ' =>SomeType' 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆