aboutsummaryrefslogtreecommitdiff
path: root/usage_examples/GetterLazyExample_post.jpage
blob: 9f4b1ba36268a07a8defe8459b31fdb2976e8b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
	}
}