首页 > 解决方案 > scala 的 List.cons 方法在哪里?

问题描述

Scala 的 List.cons 在哪里?我无法在我的设置中找到它。

scala> List.::
<console>:12: error: value :: is not a member of object List
       List.::
            ^

scala> List.cons
<console>:12: error: value cons is not a member of object List
       List.cons
            ^

如果我键入 List.[tab] 来自动完成,我会得到

scala> List.
!=   ->                    ReusableCBF    canBuildFrom   ensuring   fill        hashCode       ne           notifyAll      tabulate     wait
##   ==                    apply          concat         eq         formatted   isInstanceOf   newBuilder   range          toString     →
+    GenericCanBuildFrom   asInstanceOf   empty          equals     getClass    iterate        notify       synchronized   unapplySeq

标签: scala

解决方案


它在类上List,而不是在对象上List

scala> List(1).::
   def ::[B >: Int](elem: B): List[B]

推荐阅读