1
스칼라 코드 :
object Path {
def unapply(s:String):Some[String] = Some(s)
}
val s = "hello world"
val h = "hello"
s match {
case Path(s"$h world") => println("Get hello")
case _ => println("???")
}
나는 패턴 매칭에 s"$var"
을 사용하려고하지만, 컴파일 할 수 없습니다
<console> error: method s is not a case class, nor does it have
an unapply/unapplySeq member
case Path(s"$h world") => println("Get hello")
스칼라 컴파일 할 수없는 이유는 무엇입니까? 그것은 잘 작동하고
s match {
case Path(p) if p == s"$h world" => println("Get hello")
case _ => println("???")
}
: 나는 if
절에 넣을 경우
.
왜 스칼라에서는 컴파일 할 수 없습니까?
당신이 [비디오]에 관심이있을 수 있습니다 (http://www.youtube.com/watch?v=tcQgNEFAVjI&t=41m5s); 그것은 다르지만 일을합니다. – eruve