【发布时间】:2013-09-13 13:30:12
【问题描述】:
在申请了一些case 之后,我尝试match。有点像nested cases/matches:
val x1 = 2 // or 1, 3 ...
val str = x1 match { // scala.MatchError: 1 (of class java.lang.Integer)
case x if(x > 1) => "x"+x match {case "x1" => "yes"}
// updated:
case _ => "nope"
}
println (str)
它因scala.MatchError 异常而失败。
有可能吗?我好像见过类似的东西。
线程“主”scala.MatchError 中的异常:x2(类 java.lang.String) 在 pattern_matching.PatternMatchingTest$delayedInit$body.apply(PatternMatchingTest.scala:32) 在 scala.Function0$class.apply$mcV$sp(Function0.scala:40) 在 scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) 在 scala.App$$anonfun$main$1.apply(App.scala:71) 在 scala.App$$anonfun$main$1.apply
【问题讨论】: