2
object RegexImplicits{
  implicit class RegexWrapper(r: scala.util.matching.Regex) {
    def matches(s: CharSequence): Boolean = r.pattern.matcher(s).find
  }

  def something(s:String):Boolean = s == "42"
}
import RegexImplicits._

//This errors with the message
//<console>:16: error: missing arguments for method matches in class RegexWrapper;
//follow this method with `_' if you want to treat it as a partially applied function
//              "a".r.matches _ 
"a".r.matches _ 

//But this works fine...
something _

something _機能するのに、暗黙のクラスを含む値が機能しないのはなぜですか?

これは暗黙のクラスと関係がありますか、それとも赤いニシンであり、別の問題が発生していますか?

4

1 に答える 1

3

om-nom-nom が指摘したように、これは scala コンパイラの既知のバグです。

http://issues.scala-lang.org/browse/SI-3218

Paulp の推奨事項は、ドット フリー フォームを使用するか、_ を括弧で囲むことです。

"a".r matches _

また

"a".r.matches(_)
于 2013-04-15T22:55:02.607 に答える