Mukesh kumar saini Mukesh kumar saini - 3 months ago 7
Scala Question

var initalization at the time of declaration in scala

I am confused with following initialization

var in = None: Option[FileInputStream]


however what I know is that

var varName : type = _ // default value initialization
var varName : type = someValue // other than default intitalization


but what is

var in = None: Option[FileInputStream]


Please help
Thanks

Answer
//  [name]  =  [value] : [type]
var in      =  None    : Option[FileInputStream] 

// can equivalently be written as: 
var in: Option[FileInputStream] = None    

This creates a variable of type Option[FileInputStream], with the initial value None. To learn more about Scala's Option type, see http://www.scala-lang.org/api/current/#scala.Option