Scala Puzzlers提出了这个“益智游戏”:
scala> List("1", "2").toSet() + "3"
warning: there was one deprecation warning; re-run with -deprecation for details
res13: String = false3
该解释说明上述代码消除了:
(List("1", "2").toSet[Any] apply ()) + "3"
但为什么以下内容不会返回false
?
scala> Set("1")()
<console>:11: error: not enough arguments for method apply: (elem: String)Boolean in trait GenSetLike.
Unspecified value parameter elem.
Set("1")()
^