You can use curly braces to interpolate expressions into string literals:
def f(x: String) = x + x
val a = "A"
s"${a}" // "A"
s"${f(a)}" // "AA"
Without the braces, scala would only interpolate the identifier after the $
(in this case f
). Since there is no implicit conversion from f
to a String
this is an exception in this example:
s"$f(a)" // compile-time error (missing argument list for method f)