Scala模式匹配和逻辑不

贾克斯塔克

我有:

 x match { 
  case a: SomeType => doSomething()
  case _ => doSomethingElse()
 }

有没有办法检查“ a”不是给定类型?

像这样:

x match { 
  case !(a: SomeType) => doSomething()
  case _ => doSomethingElse()
}

编辑:我同意这个问题可能不是很清楚,但是我的兴趣主要是合乎逻辑的,并且已经得到回答。

佩德罗·科雷亚·路易斯

像这样:

x match { 
  case a: if !a.isInstanceOf[MyFirst] => doSomething()
  case b: MySecond => doSomething()
  case _ => doSomethingElse()
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章