That's right. Using the return outputs, you can more or less give a name to the field identifier. In fact, you can even say
val ` ` = 0
which defines a variable named (one space character).
The literal definition of identifiers is useful in two cases. In the first case, when Scala has already reserved one word with the name Scala, and you need to use the Java library, which does not care about this (and, of course, why it should).
Otherwise, the case statement is used. The convention is that lowercase names refer to matching variables, while uppercase names refer to identifiers from the outer scope. In this way,
val A = "a" val b = "b" "a" match { case b => println("b") case A => println("A") }
prints "b" (if the compiler was dumb enough not to fail, saying that case A were unavailable). If you want to refer to the originally defined val b , you need to use backlinks as a marker.
"a" match { case `b` => println("b") case A => println("A") }
What prints "A" .
Add . This recent question has a more advanced use case with angle brackets (<gt;) , where backlinks were necessary for the compiler to digest the code for the setter method (which itself uses some kind of “magic syntax”).
Debilski Jul 04 2018-11-22T00: 00Z
source share