When I was reading spark source code here, I saw code like $(a_variable)
.
What does it mean?
I copy the code here:
final val blockSize
That isn't special Scala syntax, it's a method name. In Scala $
is a legal identifier. The method is inherited from the org.apache.spark.ml.param.Param
trait.
See the source.
I believe that the dollar sign is usually used for string interpolation. What that means is that if I want to use a val(ue)/var(iable) inside a string (denoted with an s
before the first double quotation), I can access such vals/vars using the $
sign. Otherwise, we won't be able to use vals/vars inside a string since it would not know how to escape the string characters.
Example:
val favoriteFruit = "strawberry"
val strawberryCount = 12
println(s"My favorite fruit is ${favoriteFruit}. I've had ${strawberryCount} pieces today!") // string interpolation
In your case, however it seems that $
is a shortcut to getOrDefault
the var/val (as sourced by @Michael Zajac and @kingledion...gets the value/variable. If it does not exist, gets the default value/variable). Using getOrDefault
may be a more robust solution in cases in which you expect the parameter to not always have a corresponding value, for which you can set a default value.