Mukesh kumar saini Mukesh kumar saini - 7 months ago 26
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

//  [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