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
Post a Comment