我的代码snipet有问题:
@Override
public Single<List<Order>> getOrders() {
return Single.create(subscriber -> {
List<Order> orders = new ArrayList<>();
database.beginTransaction();
Cursor cursor = database.query(OrdersSqliteTable.TABLE_NAME,
null, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
orders.add(OrdersSqliteTable.cursorToOrder(cursor));
cursor.moveToNext();
}
database.setTransactionSuccessful();
database.endTransaction();
subscriber.onSuccess(orders);
}).subscribeOn(Schedulers.io());
}
如您所见,我想返回Single订阅io调度程序。返回类型 - Single<List<OrderItem>>
,但运算符subscribeOn返回Single<Object>
。编译器用“不兼容的类型”(我使用Android的Jack编译器)向我大吼大叫有没有办法投出subscribeOn的结果? (“强制转换”运算符不起作用,因为它不支持泛型)
答案 0 :(得分:1)