【发布时间】:2016-08-13 11:53:29
【问题描述】:
我是 scala 的新手。我正在编写如下模式匹配:
val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo")
show(capitals.get("test"))
def show(x: Option[String]) = x match {
case Some(s) | None => s
}
我收到错误:
Error: illegal variable in pattern alternative
case Some(s) | None => s
^
我正在尝试查看如何实现或达到我在 java 中的 if 语句中的条件
if (str == null || str.isEmpty())
你能帮忙重写代码或指出错误吗?
问题:如何在案例模式匹配中提及或条件?
【问题讨论】: