文档说,Subject是Observer并且可以订阅Observables,但是我找不到在代码中执行此操作的方法。
提前致谢!
答案 0 :(得分:7)
样本junit代码:
@Test
public void shouldSubscribeToSubjectToObservable() throws InterruptedException {
Observable<Integer> observable = Observable.just(1, 2);
PublishSubject<Object> subject = PublishSubject.create();
subject.subscribe(o -> {
System.out.println("o = " + o);
});
observable.subscribe(subject);
Thread.sleep(1000);
}