0__ 0__ - 1 year ago 104
Scala Question

Disable false warning "possible missing interpolator"

I have some nested case classes, and for a specific serialization mechanism I need to provide a

that contains
characters. Like so

object Foo {
case class Bar() {
override def productPrefix = "Foo$Bar"

Now I get a compiler warning from this:

Warning:(53, 42) possible missing interpolator: detected interpolated identifier `$Bar`
override def productPrefix: String = "Foo$Bar"

Is there a way to disable the warning, if possible only for this instance? Scala version is 2.11.8.

Edit: I just thought I was clever:
. But the compiler even warns about this. Another solution is
, given the constraint that there are no further outer objects.

Answer Source

If there's a way to compose the string from its parts you could do something like this.

override def productPrefix = "Foo$" + "Bar"

You could also quiet the "missing interpolator" warning by actually invoking the interpolator, but escaping the $.

override def productPrefix = f"Foo$$Bar"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download