Да, он использует тот же шаблон. Смотрите ваш Скала-код:
class Sample {
def computation(): Int = 100
def fn(compute: Boolean, default: Int): Int = {
lazy val c = computation()
if (compute) c*c else default
}
}
скомпилировано с помощью скаляка и декомпилировано с помощью JAD:
public class Sample implements ScalaObject
{
public int computation()
{
return 100;
}
public int fn(boolean compute, int default)
{
VolatileIntRef bitmap$0$1 = new VolatileIntRef(0);
IntRef c$lzy$1 = new IntRef(0);
return compute ? c$1(c$lzy$1, bitmap$0$1) * c$1(c$lzy$1, bitmap$0$1) : default;
}
private final int c$1(IntRef intref, VolatileIntRef volatileintref)
{
if((volatileintref.elem & 1) == 0)
synchronized(this)
{
if((volatileintref.elem & 1) == 0)
{
intref.elem = computation();
volatileintref.elem = volatileintref.elem | 1;
}
BoxedUnit _tmp = BoxedUnit.UNIT;
}
return intref.elem;
}
public Sample()
{
}
}