Get Boolean Value from VM Parameter in Scala

idioms, scala

Solution

Scala has the `sys.props` object which wraps the Java system properties API, so you can deal with `Option` instead of `null`.

sys.props.get("property.name") exists (_ equalsIgnoreCase "true")

Problem

How do I elegantly get a Boolean value from a VM parameter? My solution is not as easy as I have to test if it is null otherwise I will get IllegalArgumentException have to convert the entire String to upper or lower case and test if it is exactly "false" or "true" otherwise I will have the same exception thrown at my face. i.e. ``` val property = System.getProperty("some.property.name") property != null && property.toLowerCase == "true" ``` Is there another way out of this? Thanks.

Original source