How to check for null or false in Scala concisely?

Viewed 55967

In Groovy language, it is very simple to check for null or false like:

groovy code:

def some = getSomething()
if(some) {
// do something with some as it is not null or emtpy 

}

In Groovy if some is null or is empty string or is zero number etc. will evaluate to false. What is similar concise method of testing for null or false in Scala? What is the simple answer to this part of the question assuming some is simply of Java type String?

Also another even better method in groovy is:

def str = some?.toString()

which means if some is not null then the toString method on some would be invoked instead of throwing NPE in case some was null. What is similar in Scala?

7 Answers
Related