【发布时间】:2018-11-22 11:19:20
【问题描述】:
我正在玩一些 Scala 代码,但遇到了一条我不太理解的错误消息。下面是我的代码
val ignoredIds = Array("one", "two", "three")
def csNotify(x : Any): String = {
case org: String if !ignoredIds.contains(x) =>
println( s" $x should not be here")
"one"
case org : String if ignoredIds.contains(x) =>
println(s"$x should be here")
"two"
}
csNotify("four")
控制台输出是我必须知道默认函数的参数。错误点似乎指向“ String = ”。为什么会这样?该函数应该检查这两种情况并返回一个字符串?
【问题讨论】: