Skip to content

Commit 935822c

Browse files
committed
instantiate EMPTY lazily
1 parent 3cc254c commit 935822c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/java/rx/Observable.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,15 @@ public final static <T> Observable<T> defer(Func0<Observable<T>> observableFacto
10291029
return create(new OnSubscribeDefer<T>(observableFactory));
10301030
}
10311031

1032-
/** An empty observable which just emits onCompleted to any subscriber. */
1033-
private static final Observable<Object> EMPTY = create(new OnSubscribe<Object>() {
1034-
@Override
1035-
public void call(Subscriber<? super Object> t1) {
1036-
t1.onCompleted();
1037-
}
1038-
});
1032+
/** Lazy initialized Holder for an empty observable which just emits onCompleted to any subscriber. */
1033+
private static final class EmptyHolder {
1034+
final static Observable<Object> INSTANCE = create(new OnSubscribe<Object>() {
1035+
@Override
1036+
public void call(Subscriber<? super Object> subscriber) {
1037+
subscriber.onCompleted();
1038+
}
1039+
});
1040+
}
10391041

10401042
/**
10411043
* Returns an Observable that emits no items to the {@link Observer} and immediately invokes its
@@ -1055,7 +1057,7 @@ public void call(Subscriber<? super Object> t1) {
10551057
*/
10561058
@SuppressWarnings("unchecked")
10571059
public final static <T> Observable<T> empty() {
1058-
return (Observable<T>)EMPTY;
1060+
return (Observable<T>) EmptyHolder.INSTANCE;
10591061
}
10601062

10611063
/**

0 commit comments

Comments
 (0)