You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -58,17 +58,17 @@ about: Thanks to <a href="http://brenocon.com/">Brendan O'Connor</a>, this cheat
58
58
|`x.asInstanceOf[String]`| 类型转换 (运行时) |
59
59
|`case class Foo; case object Bar`|遇到关键字 "case" ,编译器会为其生成 equals & hashcode 方法,并且其构造参数都是只读的公开fields|
60
60
| <h2id="functiondeclaration">函数声明</h2> ||
61
-
|`(i:Int) => i+1`|creates a function.|
62
-
|`var func = (i:Int) => i+1`|creates a function and stores it in a variable|
63
-
|`func(5)`|executing the function above|
64
-
|`def func = (i:Int) => i+1`|creates a function each time the method is called and returns that function, not i+1|
65
-
|`val func:(Int) => String = (i:Int) => i.toString`|just so you know the syntax of a type of a function :)|
66
-
|`def takesFunction(f:(Int) => String) = f(5)`|method that takes the function above as a parameter and calls it. compiler figures out the return type "string" for you.|
67
-
|`def method(i:Int) = t.toString;val func = method _`|appending an "_" converts any method into a function|
68
-
|`takesFunction(method)`|is also possible, the compiler does the conversion for you in obvious cases|
69
-
|`def method(s:String)(s2:String) = s+" "+s2`<br>`val intermediate:(String)=>String = method("hello")`<br>`intermediate("world")`|parameter lists revisited: the intermediate, "incomplete method calls" are functions. the result of the last call is "hello world"|
70
-
|`func(5)`<br>`func.apply(5)`|what you are actually calling is the apply-method of a function instance, but you don't have to explicitly write that. if no method name is given, the compiler assumed you want to call "apply"|
71
-
|`def createFunction = (i:Int) => i+1`<br>`createFunction(5)`|if you have read the syntax section above, you can figure out what happens here. first, createFunction is called without () and without a parameter. then, 5 is applied to the apply method of the *result* of createfunction|
61
+
|`(i:Int) => i+1`|创建一个函数.|
62
+
|`var func = (i:Int) => i+1`|创建函数并把它声明为一个变量 func: Int => Int = <function1>|
63
+
|`func(5)`|执行上面的函数|
64
+
|`def func = (i:Int) => i+1`|每次调用方法的时候都创建一个函数并返回该函数,不是i+1 func: Int => Int|
0 commit comments