ant2009
ant2009

Reputation: 22486

Trying to convert a kotlin method to java that uses RxJava

Android Studio 3.1 RC 2
kotlin 1.2.30

Signature for the fetchMessage

Single<Response> fetchMessage(final String messageId);

The kotlin code that I am trying to convert to Java. However, I am not sure where the returns are? As I am new to kotlin and lambda.

private fun getMessage(messageId: String): Observable<State> {
        return repository
                .fetchMessage(messageId)
                .flatMap {
                    Single.fromCallable<State>({
                        update(messageId, it, State.COMPLETED)
                        State.COMPLETED
                    })
                }
                .toObservable()
}

This is my attempt at trying to convert it. However, the compiler complains of a missing return.

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();
}

Many thanks for any suggestions,

Upvotes: 0

Views: 233

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

because it is missing the return statement. It should be

public Single<State> call(final Response response) {
     return Single.fromCallable(new Callable<State>() {

Upvotes: 3

Related Questions