How to suppress “match is not exhaustive!” warning in Scala

前端 未结 4 2042
我在风中等你
我在风中等你 2020-12-11 00:09

How can I suppress the \"match is not exhaustive!\" warning in the following Scala code?

val l = \"1\" :: \"2\" :: Nil
l.sliding(2).foreach{case List(a,b) =&         


        
4条回答
  •  渐次进展
    2020-12-11 01:12

    Making it complete with ; case _ => ??? is pretty short. ??? just throws an exception. You can define your own if you're using 2.9 or before (it's new in 2.10).

    It really is pretty short compared to what you need for a match annotation:

    (: @unchecked)
    ; case _ => ???
                  ^  One more character!
    

    It doesn't throw a MatchError, but does that really matter?

提交回复
热议问题