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