简体   繁体   中英

what does it mean in scala val _x and val x_

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?

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM