Using Option all over the place feels a bit awkward. Am I doing something wrong?

Posted by Geo on Stack Overflow See other posts from Stack Overflow or by Geo
Published on 2010-03-19T11:34:25Z Indexed on 2010/03/19 11:41 UTC
Read the original article Hit count: 120

Filed under:
|

As a result of articles I read about the Option class which helps you avoid NullPointerException's, I started to use it all over the place. Imagine something like this:

var file:Option[File] = None

and later when I use it:

val actualFile = file.getOrElse(new File("nonexisting"))
if(actualFile.getName.equals("nonexisting")) { // instead of null checking

}
else { // value of file was good

}

Doing stuff like this doesn't feel all that "right" to me. I also noticed that .get has become deprecated. . Is this sort of stuff what you guys are doing with Option's too, or am I going the wrong way?

© Stack Overflow or respective owner

Related posts about scala

Related posts about option