mirror of
https://github.com/tiennm99/lombok.git
synced 2026-05-25 13:39:24 +00:00
917518bbea
note: this example shows how lazy getter would work once issue 160 is no more
26 lines
597 B
Plaintext
26 lines
597 B
Plaintext
public class GetterLazyExample {
|
|
private double[] $lombok$lazy1v;
|
|
private volatile boolean $lombok$lazy1i;
|
|
private final Object $lombok$lazyLock = new Object[0];
|
|
|
|
public double[] getCached() {
|
|
if (!this.$lombok$lazy1i) {
|
|
synchronized (this.$lombok$lazyLock) {
|
|
if (!this.$lombok$lazy1i) {
|
|
this.$lombok$lazy1v = expensive();
|
|
this.$lombok$lazy1i = true;
|
|
}
|
|
}
|
|
}
|
|
return this.$lombok$lazy1v;
|
|
}
|
|
|
|
private double[] expensive() {
|
|
double[] result = new double[1000000];
|
|
for (int i = 0; i < result.length; i++) {
|
|
result[i] = Math.asin(i);
|
|
}
|
|
return result;
|
|
}
|
|
}
|