[英]Is it possible to declare return type for closure?
I'm learning closure in scala programming language.我正在学习 scala 编程语言的闭包。
For example:例如:
val a = (x:Int, y:Int) => x + y;
a(1, 2)
will give me 3
.会给我
3
。 the closure a
works like a function (Int, Int):Int
.闭包
a
function (Int, Int):Int
。
Is it possible to declare the return type for closure like this?是否可以像这样声明闭包的返回类型?
val a = (x:Int, y:Int):Int => x + y;
a(1, 2)
Is it possible?可能吗?
This syntax is impossible ( val a = (x:Int, y:Int):Int => x + y
), but you can declare type for a
:这种语法是不可能的(
val a = (x:Int, y:Int):Int => x + y
),但您可以为a
声明类型:
val a: (Int, Int) => Int = (x, y) => x + y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.