Using extract<T?>
is the better way than Config.hasPath()
. extract<T?>
returns T
when the path exists and null
when it does not exist.
val config = ConfigFactory.parseString("""key = 10""")
val key = config.extract<Int?>("key")
val foo = config.extract<Int?>("foo")
println(key) // 10
println(foo) // null