Skip to content

Commit

Permalink
Optimized Null value lazy
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
  • Loading branch information
tonydamage committed Jan 27, 2021
1 parent 16c24bc commit 62865c3
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -8,7 +8,7 @@

public class Lazy<T> extends AbstractLazy<T> implements java.util.function.Supplier<T> {

private static final Lazy NULL = Lazy.instant(null);
private static final Lazy<?> NULL = new Lazy<>(null);

private Lazy(Object supplier) {
super(supplier);
Expand All @@ -19,12 +19,15 @@ public static final <T> Lazy<T> from(Supplier<? extends T> supplier) {
}

public static <T> Lazy<T> instant(T value) {
return new Lazy<T>(value);
if(value == null) {
return nullValue();
}
return new Lazy<>(value);
}

@SuppressWarnings("unchecked")
public static <T> Lazy<T> nullValue() {
return NULL;
return Lazy.class.cast(NULL);
}

@Override
Expand Down

0 comments on commit 62865c3

Please sign in to comment.