如何从.map运算符在HandlerThread上调用.start

时间:2018-12-21 10:31:41

标签: android java-8 reactive-programming rx-java2 android-handlerthread

我正在学习如何在Android中处理和使用函数式编程。因此,我开发了以下代码。我想将HandlerThread视为可观察到的,但是当我尝试从以下位置调用.start()时 .map()运算符,我收到以下错误:

    no instances of type variable(s) R exists so that  void conforms to R

请让我知道为什么出现此错误以及如何解决它。

代码

public Single<HandlerThread> getObsInitializedHandlerThread() {
    this.mMyHandlerThread = new MyHandlerThread(NAME_MY_HANDLER_THREAD);
    return Single.just(this.mMyHandlerThread);
}

@Override
protected void onResume() {
    super.onResume();
    String TAG_LOG = ActMain.TAG_LOG + "." + "onResume()";
    Log.v(TAG_LOG, ":");

    this.getObsInitializedHandlerThread()
            .map(mMyHandlerThread -> mMyHandlerThread.start());
}

private class MyHandlerThread extends HandlerThread {

    public MyHandlerThread(String name) {
        super(name);
        String TAG_LOG = ActMain.class.getSimpleName() + "." + "MyHandlerThread() Constructor";
        Log.v(TAG_LOG, ":");
    }

    @Override
    protected void onLooperPrepared() {
        super.onLooperPrepared();
        String TAG_LOG = ActMain.class.getSimpleName() + "." + onLoopPrepared()";
        Log.v(TAG_LOG, ":");
    }
}

1 个答案:

答案 0 :(得分:0)

在地图中,您始终需要返回一个值(T),不能返回空值,所以您可以尝试

body = body.replace(/(?:href=(?:"|'))((?:(?:(?:\/)))?(?:(?:\.\.\/)*)?(?:(?:[a-zA-Z0-9-_]+\/?)+)?(?:(?:[a-zA-Z0-9-_])*(\.[a-zA-Z0-9-_]{1,})+)?)(?:"|')/g, (a, b) => {
    return `href="${config.get('baseUrl')}api/preview?url=${new URL(b, target).href}"`;
});*/