In Java, when using an object across multiple threads (and in general), it is good practice to make fields final. For example,
public class ShareMe {
private final MyObject obj;
public ShareMe(MyObject obj) {
this.obj = obj;
}
}
In this case, the visibility of obj will be consistent across multiple threads (let's assume obj has all final fields as well) since it is safely constructed using the final keyword.
In scala, it doesn't appear val compiles down to a final reference, but rather val is semantics in scala that prevents you from reassigning a variable (Scala final variables in constructor). If scala constructor variables are not defined as final, will they suffer from the same problem (when using these objects in actors)?