java.lang.Boolean#getBoolean(String)
如果您不反对调用 Java API 类,则完全符合您的要求:
scala> import java.lang.Boolean
import java.lang.Boolean
scala> Boolean.getBoolean("some.property.name")
res0: Boolean = false
scala> System.setProperty("foo", "true")
res1: String = null
scala> Boolean.getBoolean("foo")
res2: Boolean = true
scala> System.setProperty("bar", "false")
res3: String = null
scala> Boolean.getBoolean("bar")
res4: Boolean = false
scala> System.setProperty("baz", "lorem ipsum")
res5: String = null
scala> Boolean.getBoolean("baz")
res6: Boolean = false