I saw some scala code that assign \"_\" to a field of class, what does it mean ? Thanks
private var tk: TaggedKey = _
It means: assign default value. Default value is defined as null
, 0
or false
depending on the target type.
It is described in 4.2 Variable Declarations and Definitions of the The Scala Language Specification:
A variable definition
var x : T = _
can appear only as a member of a template. It introduces a mutable field with type T and a default initial value. The default value depends on the type T as follows:
0
- ifT
is Int or one of its subrange types,
0L
- ifT
is Long,
0.0f
- ifT
is Float,
0.0d
- ifT
is Double,
false
- ifT
is Boolean,
()
- ifT
is Unit,
null
- for all other typesT
.