scala> def judge(func:()=> Boolean) {
| val result = func()
| println(result)
| }
judge: (func:() => Boolean)Unit
scala> def compare = { 6 > 4 }
compare: Boolean
scala> judge(compare)
<console>:10: error: type mismatch;
found : Boolean
required:() => Boolean
judge(compare)
^
scala> def compare() = { 6 > 4 }
compare:()Boolean
scala> judge(compare)
true
什麼def compare() = { 6 > 4 }
手段? 兩個'比較'功能有什麼區別? 我很困惑。Scala中的這個定義是什麼意思?
謝謝。
我讀過的Scala編程和你的答案,我明白了。非常感謝你。 – user3190192