=>(scala)

1Function<n>[A[,B,...],T]  :a function that takes parameters of type A[,B...], and returns a value of type T.

2=>()  :A function that returns Unit is also known as a procedure, normally a method that's called only for its side effect.

3f(param: => T)  :it's a "by-name parameter", meaning that is evaluated every time it's used within the body of the function, and not before. Ordinary "by-value" parameters are evaluated before entry into the function/method.

 

 

=> is syntactic sugar for creating instances of functions. Recall that every function in scala is an instance of a class.

val f: Function1[Int,String] = myInt => "my int: "+myInt.toString
val f2: Int => String = myInt => "my int v2: "+myInt.toString
f: (Int) => String = <function1>

posted on 2017-09-20 07:01  satyrs  阅读(121)  评论(0编辑  收藏  举报

导航