Skip to content

Commit 02f4a60

Browse files
committed
Attempt to fix #108
1 parent b148dec commit 02f4a60

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

core/src/main/java/fj/P1.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import fj.data.Option;
1010
import fj.data.Validation;
1111
//import fj.data.*;
12-
import fj.function.Try0;
12+
1313

1414
public abstract class P1<A> implements F0<A> {
1515

@@ -216,22 +216,22 @@ public P1<A> memo() {
216216
final P1<A> self = this;
217217
return new P1<A>() {
218218
private final Object latch = new Object();
219-
@SuppressWarnings({"InstanceVariableMayNotBeInitialized"})
220-
private volatile SoftReference<A> v;
219+
private volatile SoftReference<Option<A>> v = null;
221220

222221
public A _1() {
223-
A a = v != null ? v.get() : null;
224-
if (a == null)
222+
Option<A> o = v != null ? v.get() : null;
223+
if (o == null) {
225224
synchronized (latch) {
226-
if (v == null || v.get() == null) {
227-
a = self._1();
228-
v = new SoftReference<A>(a);
229-
} else {
230-
a = v.get();
225+
o = v != null ? v.get() : null;
226+
if (o == null) {
227+
o = Option.some(self._1());
228+
v = new SoftReference<>(o);
231229
}
232230
}
233-
return a;
231+
}
232+
return o.some();
234233
}
234+
235235
};
236236
}
237237

0 commit comments

Comments
 (0)