三冒号 Scala
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7621014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Triple colon Scala
提问by providence
I'm trying to pick up some scala. Reading through examples I came across this impossible-to-google nugget:
我正在尝试获取一些 Scala. 通读示例,我发现了这个不可能通过谷歌搜索的金块:
case 3 => l ::: List(3)
What does the triple colon accomplish?
三结肠有什么作用?
回答by Aaron Novstrup
To add to gkamal's answer, it's important to understand that methods whose names end in a colon are right-associative. So writing l ::: List(3)is the same as writing List(3).:::(l). In this case it doesn't matter since both operands are lists, but in general you'll need this knowledge to find such methods in the scaladocs.
要添加到gkamal 的答案中,重要的是要了解名称以冒号结尾的方法是右结合的。所以写作和写作l ::: List(3)是一样的List(3).:::(l)。在这种情况下,这并不重要,因为两个操作数都是列表,但通常您需要这些知识才能在 scaladocs 中找到此类方法。
It also helps to know that the scaladocshave a comprehensive index of all methods (and classes, etc) with symbolic names. You can reach it by clicking on the #in the upper-left corner.

