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 回答