1

I'm confused with below the following two declarations :

val _x
val x_

What does it mean and why we use underscore sometimes for declaring variables and functions?

eliasah
  • 39,588
  • 11
  • 124
  • 154
Yogesh
  • 11
  • 5

3 Answers3

5

Those are just part of the name with no special meaning. You will have to ask the author why he chose to use those names.

There are many places where underscore do have special meaning however, take a look at What are all the uses of an underscore in Scala?

puhlen
  • 8,400
  • 1
  • 16
  • 31
3

They're nothing special. Underscores are allowed in variable names in Scala (but this is discouraged, as the linked style guide mentions).

Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54
0

This is just a simple convention, no any special meaning and rules. How ever convention is like

var _a: Option[Double] = None
def z = _variable
def b_=(newVal: Double) { _x = Some(newVal)}

I hope thi details helps UnderScore Magic

koiralo
  • 22,594
  • 6
  • 51
  • 72