Dollar sign escape in line interpolation

How can I avoid the dollar sign in string interpolation?

def getCompanion(name: String) = Class.forName(s"my.package.$name\$") // --> "error: unclosed string literal" 
+80
scala string-interpolation
Jun 01 '13 at 17:51
source share
1 answer

Just double it

 scala> val name = "foo" name: String = foo scala> s"my.package.$name$$" res0: String = my.package.foo$ 
+114
Jun 01 '13 at 18:01
source share



All Articles