Scala's '::' operator, how does it work?

前端 未结 4 1028
死守一世寂寞
死守一世寂寞 2020-11-29 00:27

In Scala, I can make a caseclass, case class Foo(x:Int), and then put it in a list like so:

List(Foo(42))

Now, nothing strange

4条回答
  •  难免孤独
    2020-11-29 00:57

    It ends with a :. And that is the sign, that this function is defined in the class to the right (in List class here).

    So, it's List(Foo(2)).::(Foo(40)), not Foo(40).::(List(Foo(2))) in your example.

提交回复
热议问题