Hi guys. Here is an example about lazy
final class LazyCell {
lazy val value = 12
}
then i decompile class, find this
public final class LazyCell {
private int value;
private volatile boolean bitmap$0;
private int value$lzycompute() {
synchronized(this){} //❓ why do this? and i think it should enclose try-catch
try {
if (!this.bitmap$0) {
this.value = 12;
this.bitmap$0 = true;
}
} catch (Throwable var3) {
throw var3;
}
return this.value;
}
public int value() {
return !this.bitmap$0 ? this.value$lzycompute() : this.value;
}
}
Can some scala guru please explain why synchronized(this){}
not synchronized(this){ try -catch }
?
scala version is 2.13.6