我必须调用返回Option[List[Obj]]
的方法。
打电话后,我需要遍历List并打印Obj属性。
object Tester{
def main(args:Array[String]) {
val ymlFilename ="some.yml";
val entities: Option[QueryEntities] = InputYamlProcessor.process(ymlFilename)
for( e: QueryEntities <- entities ){
/// this is not working
//How to access the columnFamily, fromData and toDate ?
}
}
完整样本
https://gist.github.com/shatestest/fdeaba767d78e171bb6c08b359fbd1bf
答案 0 :(得分:0)
最具标志性的方法是使用scala来解包值,即使用模式匹配来解包值。
entities match {
case Some(queryEntities: QueryEntities) =>
queryEntities.entities.foreach { case e =>
println(e.columnFamily)
println(e.fromDate.getOrElse("defaultFromDateHere")
println(e.toDate.getOrElse("defaultToDateHere"))
}
case None => println("No value")
}