Hello all,
I recently came across the following code in our codebase:
@volatile def doSomething = { /** do the thing */ }
I was immediately suspicious and created the following test
class Test {
@volatile private[this] var something = "something"
@volatile def doSomething = { println(something) }
}
$ scalac test.scala
$ javap -p Test.class
Compiled from "test.scala"
public class Test {
private volatile java.lang.String something;
public void doSomething();
public Test();
}
As you can see the @volatile on the var translates into a volatile variable in Java but the @volatile on the def is silently dropped.
This makes sense since a @volatile def is nonsensical but I was surprised that there was no compiler warning for this.
Should this be considered a bug?
Ben Darfler