An Excerpt from Programming in Scala [1]:
A literal identifier is an arbitrary string enclosed in back ticks (`...`)
. Some examples of literal identifiers are:
`x` `<clinit>` `yield`
The idea is that you can put any string that's accepted by the runtime as an identifier between back ticks. The result is always a Scala identifier. This works even if the name contained in the back ticks would be a Scala reserved word. A typical use case is accessing the static yield
method in Java's Thread
class. You cannot write Thread.yield()
because yield
is a reserved word in Scala. However, you can still name the method in back ticks, e.g., Thread.`yield`()
.
In short, with `x`
you are matching against the value of x
. With x
you are creating a new variable that will match anything and save the result to x
.
[1] M. Odersky, L. Spoon, B. Venners, Programming in Scala, 2nd ed, Walnut Creek: Artima Press 2010, pp. 109 http://www.artima.com/pins1ed/functional-objects.html#i1517246665-1