Checking if a value is assigned to a boolean variable in specs

1.5k views Asked by At

In specs bdd framework(http://code.google.com/p/specs), i can check if a value is assigned to a string or not using :

SomeClass.strVal == null mustBe false

Now, suppose the class has a boolean value boolVal. How to check if a value true or false was assigned to boolVal or not ?

Please Help Thanks

1

There are 1 answers

2
Ken Wayne VanderLinde On BEST ANSWER

Acccording to this page, the Boolean class derives from AnyVal. Therefore boolean is a value type and no boolean variable can be null. In fact, since Scala runs atop the java pplatform, it probably has the default value of false

In general, it is not good practice to leave variable uninitialized. When a variable is declared, give it a value. This alleviates the need to do these kinds of checks.