Scala:来自'if'语句的奇怪结果

时间:2014-11-18 10:07:37

标签: scala if-statement

尝试使用Scala 2.10.3'条件'语句:

scala> val index = "male-names"
index: String = male-names

scala>  val kind = if (index == "male-mames") "mn" else "fn"
kind: String = fn

为什么'善'得到“fn”而不是“mn”?

另一方面,以下情况仍然存在:

scala> index == "male-names"
res28: Boolean = true

scala> index
res29: String = male-names

1 个答案:

答案 0 :(得分:1)

scala> val index = "male-names"
index: String = male-names

有一点拼写错误

scala>  val kind = if (index == "male-mames") "mn" else "fn"
                                      ^
kind: String = fn