What are all the uses of an underscore in Scala?

后端 未结 7 1162
南笙
南笙 2020-11-21 07:24

I\'ve taken a look at the list of surveys taken on scala-lang.org and noticed a curious question: \"Can you name all the uses of “_”?\". Can you? If yes, please do so here.

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 07:49

    There is a specific example that "_" be used:

      type StringMatcher = String => (String => Boolean)
    
      def starts: StringMatcher = (prefix:String) => _ startsWith prefix
    

    may be equal to :

      def starts: StringMatcher = (prefix:String) => (s)=>s startsWith prefix
    

    Applying “_” in some scenarios will automatically convert to “(x$n) => x$n ”

提交回复
热议问题