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 _
有效但涉及隐式类的值不起作用?
这是否与隐式类有关,还是红鲱鱼,我遇到了不同的问题?
答案 0 :(得分:3)
事实证明,om-nom-nom指出,这是scala编译器中的已知错误。
http://issues.scala-lang.org/browse/SI-3218
Paulp建议使用点自由形式或用括号括起_。
"a".r matches _
或
"a".r.matches(_)