Scala if Statements

来源:互联网 发布:sql server log工具 编辑:程序博客网 时间:2024/05/23 01:16

What’s different in Scala is that if statements and almost all other statements in Scala are actually expressions that return values. If it’s true, then the corresponding block is evaluated. Otherwise, the next branches are tested and so forth.

code example :

val configFile = new java.io.File("somefile.txt")val configFilePath = if (configFile.exists()) {    configFile.getAbsolutePath()} else {    configFile.createNewFile()    configFile.getAbsolutePath()}


Ref

《Programming Scala》

0 0
原创粉丝点击