0

RxJava 的 startFuture(...) 接受一个Func0(不带参数的函数)返回一个 Future。

但是,我有一个带有 3 个参数的函数,可以表示为Func3<type, type, type, Future>. 我编写了这个函数,它应该关闭 Func3 并将其作为 Func0 的结果返回:

public Func0 convertToFunc0(final Func3<type 1, type 2, type 3, Future> f)
{
    return new Func0() {
        @Override
        public void call() {
            f.call(???);
        }
    };
}

假设我已经为“type 1”、“type 2”等插入了适当的类型,我怎样才能访问 的参数f以便我可以“关闭”它们?关于 RxJava 的功能部分,我真的找不到任何文档,我查看了源代码,但还没有找到任何地方。

4

1 回答 1

1

怎么样

public Func0 convertToFunc0(final Func3<type 1, type 2, type 3, Future> f, final type1 param1, final type2 param2, final type3 param3)
{
    return new Func0() {
        @Override
        public void call() {
            f.call(param1, param2, param3);
        }
    };
}

如果param1和不是线程安全的param2param3则需要注意潜在的竞争条件。

于 2014-03-26T02:06:16.297 回答