-
Notifications
You must be signed in to change notification settings - Fork 44
@LazyGetter
peichhorn edited this page Jun 30, 2012
·
1 revision
See lombok issue 160
import lombok.LazyGetter;
public class LazyGetterExample {
@LazyGetter
private final double[] cached = expensive();
private double[] expensive() {
double[] result = new double[1000000];
for (int i = 0; i < result.length; i++) {
result[i] = Math.asin(i);
}
return result;
}
}
public class LazyGetterExample {
private volatile boolean $cachedInitialized;
private final Object[] $cachedLock = new Object[0];
private double[] cached;
public double[] getCached() {
if (!this.$cachedInitialized) {
synchronized (this.$cachedLock) {
if (!this.$cachedInitialized) {
this.cached = expensive();
this.$cachedInitialized = true;
}
}
return this.cached;
}
}
private double[] expensive() {
double[] result = new double[1000000];
for (int i = 0; i < result.length; i++) {
result[i] = Math.asin(i);
}
return result;
}
}
(Documentation pending)
Nothing to configure yet.
I am not able to run @Action. If I provide Action1 implementation it works.
implementation private static Action1 println() { return new Action1() { public void apply(final Object o) { System.out.println(o); } };
pom : com.github.peichhorn lombok-pg 0.11.3
<dependency>
<groupId>com.github.peichhorn</groupId>
<artifactId>lombok-pg</artifactId>
<version>0.11.3</version>
<classifier>runtime</classifier>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>