Mukesh kumar saini Mukesh kumar saini - 1 year ago 68
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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download