Scala placeholder syntax

后端 未结 2 881
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 12:51

There is something that I can\'t quite understand hope someone can shed some light.. I have Seq[String]

val strDeps: Seq[String] = ...

and

2条回答
  •  伪装坚强ぢ
    2021-01-13 13:44

    compareTo(_)
    

    Is a partially applied method. It just means "compareTo, but without applying the first parameter". Note that _ is not a parameter. Rather, it indicates the absence of a parameter.

    compareTo(_.reverse)
    

    Is a method taking an anonymous function as parameter, the parameter being _.reverse. That translates to x => x.reverse.

提交回复
热议问题