为什么我的匿名功能不起作用? 编译器向我显示错误
foreach((line: String) => {
我的代码:
Source.fromFile(siteDir.getPath).getLines()
.map(_.trim())
.filter(!_.isEmpty())
.foreach((line: String) => { // I got here "error: type mismatch; found : Unit required: String"
val pos = line.indexOf('=')
if (pos != -1) {
val key = line.substring(0, pos).trim()
val value = line.substring(pos + 1).trim()
readMeCache(siteId.get) + (key -> value)
}
})
解决问题的正确方法是什么?