scala - Back-quote identifier within interpolated string -


say use arbitrary identifier field name:

object { val `type` = "x" } 

how can refer in interpolated string?

i tried

object {    val `type` = "x"   override def tostring() = s"$type" } 

but got compiler error:

error: error in interpolated string: identifier or block expected     override def tostring() = s"$type" 

and if try

object {    val `type` = "x"   override def tostring() = s"$`type`" } 

i get

error: invalid string interpolation: `$$', `$'ident or `$'blockexpr expected     override def tostring() = s"$`type`" 

i think found solution, have put back-quote identifier in braces:

object {    val `type` = "x"   override def tostring() = s"${`type`}" } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -