Difference between Option(value) and Some(value)

If you look into Scala’s sources you’ll notice that Option(x) just evaluates x and returns Some(x) on not-null input, and None on null input.

I’d use Option(x) when I’m not sure whether x can be null or not, and Some(x) when 100% sure x is not null.

One more thing to consider is when you want to create an optional value, Some(x) produces more code because you have to explicitly point the value’s type:

val x: Option[String] = Some("asdasd")
//val x = Option("asdasd") // this is the same and shorter

Leave a Comment