我正在尝试转换PublishSubject:
rx.subjects.PublishSubject<String> sj = rx.subjects.PublishSubject.create();
PublishSubject<String> sj2 = RxJavaInterop.toV2Subject(sj);
但是IDE说不能应用rx.subjects.Subject&lt; T,T>到rx.subjects.PublishSubject&lt; java.lang.String中&GT;
答案 0 :(得分:2)
您无法将其转换为v2 PublishSubject
,因为主题实现是最终的并且无法包装其他主题,因此,正如方法的返回类型所示,您必须使用io.reactivex.subjects.Subject<String>
作为类型:
rx.subjects.PublishSubject<String> sj = rx.subjects.PublishSubject.create();
io.reactivex.subjects.Subject<String> sj2 = RxJavaInterop.toV2Subject(sj);