by shigemk2


match is not exhaustive 回避


パターンマッチのところに@uncheckedをつけると、match is not exhaustiveのwarningを回避できる。

object Test extends App {
  // This would normally warn "match is not exhaustive"
  // because `None` is not covered.
  def f(x: Option[String]) = (x: @unchecked) match { case Some(y) => y }
  // This would normally warn "type pattern is unchecked"
  // but here will blindly cast the head element to String.
  def g(xs: Any) = xs match { case x: List[String @unchecked] => x.head }