Benjamin Darfler
2016-07-15 14:22:52 UTC
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
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
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.