val a: A = _ - compilation error. For example:
scala> val a: String = _ <console>:1: error: unbound placeholder parameter val a: String = _ ^
What works var a: A = _ (note var instead of val ). As Chuck says in his answer, this initializes the variable with a default value. From Scala Language Specification:
0 if T is Int or one of its subband types,
0L, if T is long,
0.0f if T Float,
0.0d if T is Double,
false if T is Boolean,
() if T is a unit,
null for all other types of T.
Paul Butcher Dec 01 '11 at 11:52 2011-12-01 11:52
source share