从rxjava retrolambda表达式转换为classic

时间:2017-06-04 20:46:00

标签: android rx-android retrolambda

我使用retrolambda表达式

 _rxBus = getRxBusSingleton();
    _disposables = new CompositeDisposable();

    ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();

    _disposables
            .add(tapEventEmitter.subscribe(event -> {

             if (event instanceof EmployeeMvvmActivity.TapEvent) {
                _showTapText();
            }

            }));

一切正常。由于Roboelectric测试,我需要将retrolambda表达式转换为经典。我试过了

_disposables.add(tapEventEmitter.subscribe(new Action1<Object>() {
        @Override
        public void call(Object event) {
            if (event instanceof EmployeeMvvmActivity.TapEvent) {
                _showTapText();
            }
        }
    }));

我有错误无法解析方法'subscribe(匿名rx.functions.Action1(java.lang.object)'。

1 个答案:

答案 0 :(得分:2)

Action1来自Rx1,而您正在使用Rx2。相反,您必须使用Consumer界面。

_disposables.add(tapEventEmitter.subscribe(new Consumer<Object>() {
    @Override
    public void accept(Object event) {
        if (event instanceof EmployeeMvvmActivity.TapEvent) {
            _showTapText();
        }
    }
}));