为什么在隐式类上部分应用函数会给我一个错误? 对象RegexImplicits{ 隐式类RegexWrapper(r:scala.util.matching.Regex){ def matches(s:CharSequence):Boolean=r.pattern.matcher.find } 定义某物(s:String):布尔值=s==“42” } 导入RegexImplicits_ //这将导致消息错误 //:16:错误:类RegexWrapper中缺少方法匹配的参数; //如果要将其视为部分应用的函数,请使用“\u1”遵循此方法 //a.r.matches\u a.r.matches\u //但是这个很好用。。。 某物_
为什么为什么在隐式类上部分应用函数会给我一个错误? 对象RegexImplicits{ 隐式类RegexWrapper(r:scala.util.matching.Regex){ def matches(s:CharSequence):Boolean=r.pattern.matcher.find } 定义某物(s:String):布尔值=s==“42” } 导入RegexImplicits_ //这将导致消息错误 //:16:错误:类RegexWrapper中缺少方法匹配的参数; //如果要将其视为部分应用的函数,请使用“\u1”遵循此方法 //a.r.matches\u a.r.matches\u //但是这个很好用。。。 某物_,scala,implicit,Scala,Implicit,为什么something\u起作用,但涉及隐式类的值不起作用 这是否与隐式类有关,还是说这是一个误会,我遇到了另一个问题?正如om nom nom指出的,这是scala编译器中已知的错误 Paulp的建议是要么使用无点形式,要么用括号将uu括起来 object RegexImplicits{ implicit class RegexWrapper(r: scala.util.matching.Regex) { def matches(s: CharSequence): Boolea
something\u
起作用,但涉及隐式类的值不起作用
这是否与隐式类有关,还是说这是一个误会,我遇到了另一个问题?正如om nom nom指出的,这是scala编译器中已知的错误 Paulp的建议是要么使用无点形式,要么用括号将uu括起来
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 _
或
仅供参考(保罗·菲利普斯的建议也适用于您)
"a".r matches _
"a".r.matches(_)