scala - Difference between Option(value) and Some(value) -


i new scala !

my question is, if there case class contains member

myitem:option[string] 

when construct class, need wrap string content in:

option("some string") 

or

some("some string") 

is there difference ?

thanks!

if scala's sources you'll notice option(x) evaluates x , returns some(x) on not-null input, , none on null input.

i'd use option(x) when i'm not sure whether x can null or not, , some(x) when 100% sure x not null.

one more thing consider when want create optional value, some(x) produces more code because have explicitly point value's type:

val x: option[string] = some("asdasd") //val x = option("asdasd") // same , shorter 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -