Android Studio 3.1 RC 2
kotlin 1.2.30
fetchMessage的签名
Single<Response> fetchMessage(final String messageId);
我试图转换为Java的kotlin代码。但是,我不确定回报在哪里?因为我是kotlin和lambda的新手。
private fun getMessage(messageId: String): Observable<State> {
return repository
.fetchMessage(messageId)
.flatMap {
Single.fromCallable<State>({
update(messageId, it, State.COMPLETED)
State.COMPLETED
})
}
.toObservable()
}
这是我尝试转换它的尝试。但是,编译器抱怨缺少返回。
public Observable<TranslationChatState> translate(String messageId) {
return repository
.fetchMessage(messageId)
.flatMap(new Func1 <Response, Single<State >>() {
@Override
public Single<State> call(final Response response) {
Single.fromCallable(new Callable<State>() {
@Override
public State call() {
update(messageId, response, State.COMPLETED);
return State.COMPLETED;
}
});
} /* complains about no return here */
})
.toObservable();
}
非常感谢任何建议,
答案 0 :(得分:3)
因为它缺少return语句。它应该是
public Single<State> call(final Response response) {
return Single.fromCallable(new Callable<State>() {