Working Effortlessly with Java null in Scala

Java null in Scala


We would not repeat why null is a billion dollar mistake of Java. In our earlier post, we have already discussed how to handle nulls of Java. In this post we would take it a step further, but first a bit of recap.

Say that you have a function in Java which can potentially throw a null.

Now, the way we have been handling this in Scala has been with fold. So what we would do is

Hence, if the Option(getUser) results in None then we give the default value which is “Sky” else if it is Some then we pass it to a method called processUser which brings us back the name. Hence it is of the type User=>String

Now what is the problem with this approach, actually none but it just leads to quite some boilerplating if we are working with quite a few Java methods which…

View original post 186 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s