aboutsummaryrefslogtreecommitdiff
path: root/usage_examples/GetterLazyExample_post.jpage
diff options
context:
space:
mode:
Diffstat (limited to 'usage_examples/GetterLazyExample_post.jpage')
-rw-r--r--usage_examples/GetterLazyExample_post.jpage25
1 files changed, 25 insertions, 0 deletions
diff --git a/usage_examples/GetterLazyExample_post.jpage b/usage_examples/GetterLazyExample_post.jpage
new file mode 100644
index 00000000..76101db1
--- /dev/null
+++ b/usage_examples/GetterLazyExample_post.jpage
@@ -0,0 +1,25 @@
+public class GetterLazyExample {
+ private int[] $lombok$lazy1v;
+ private volatile boolean $lombok$lazy1i;
+ private final Object $lombok$lazyLock = new Object[0];
+
+ public int[] 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 int[] expensive() {
+ double[] result = new double[1000000];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = Math.asin(i);
+ }
+ return result;
+ }
+}