【发布时间】:2016-11-04 01:01:29
【问题描述】:
val LIST = scala.collection.mutable.MutableList[String]()
val filterF = new Function[Path, Boolean] {
def apply(x: Path): Boolean = {
println("looking into " + x)
val flag = if (x.toString.split("/").last.split("_").last.toLong < System.currentTimeMillis) {
println("considered " + x)
LIST += x.toString
return true
} else {
println("NOT considered " + x)
return false
}
return flag
}
}
我正在尝试更新函数filterF 内的外部变量LIST。但问题是println("looking into "+x)之后
行其余代码无法访问。
val flag = if (x.toString.split("/").last.split("_").last.toLong < System.currentTimeMillis) {
println("considered " + x)
LIST += x.toString
return true
} else {
println("NOT considered " + x)
return false
}
return flag
我不明白为什么这段代码无法访问。代码中是否有某些字符实际上是造成这种情况的原因?
【问题讨论】:
-
您确实需要更好地格式化您的代码。那些在线运行的东西读起来很痛苦。
-
幽默我;你试过 'System.out.println("looking into "+x)' 吗?
-
请取出脚本中的每个分号并重新粘贴。一个语句 = 一行
-
进行了编辑。希望它看起来更好。很抱歉给您带来不便。认为这是新手的错误。
-
@VijayKrishna 格式化了您问题中的代码并回答了它。请检查
标签: scala function unreachable-code