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
|`val x = "hello"`|the compiler always picks the most specific type possible, in this case java.lang.String|
74
-
|`val x:Serializable = "hello"`|you can always specify a more general one|
75
-
|`def x {print("hello world")}`|method without "=" means the method has no return type/return type is void (this is a lie) |
76
-
|`def x:Unit = {...}`<br>`def x() {...}`|leaving out the "=" at a method declaration is the same as specifying "Unit"|
77
-
|`val blocks = {{{{5}}}}`|every block has a return type that is passed back to the next outer block|
78
-
|`val block = if (a) foo else bar`|almost everything is an expression and thus, has a return type. this includes if-else-structures|
79
-
|`def x = {`<br>`if (System.currentTimeMillis() % 2 == 0) Integer.valueOf(1) else java.lang.Double.valueOf(2)`<br>`}`|here, the compiler picks the most specific supertype of both Integer and Double which is java.lang.Number (this is a lie)|
80
-
|`def x(i:Int):Int = if (i==0) 1 else i*x(i-1)`|recursive methods need an explicit return type. fail.|
73
+
|`val x = "hello"`|编译器总是会选择最可能的类型, 在这里是 java.lang.String|
74
+
|`val x:Serializable = "hello"`|你总能指定更通用的类型|
75
+
|`def x {print("hello world")}`|没有 "=" 的方法表明这个方法没有返回类型,或者返回类型为void(逗你玩呢)|
0 commit comments