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.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With