我有以下观察

Observable<TestEntity1> entity1Observable = getTestEntity1Observable();
Observable<TestEntity2> entity2Observable = getTestEntity2Observable();
....
....
...
...
Observable<TestEntity5> entity5Observable = getTestEntity5Observable();


我想使用java var args压缩这些Obsevable,而不是像下面那样增加Observable.zip中的参数数量

Observable<AggregateEntity>  aggregate = Observable.zip(entity1Observable,
               entity2Observable, entity3Observable, entity4Observable,
               entity5Observable, aggregateEntity::setData);

public AggregateEntity setData(TestEntity1 entity1Observable, TestEntity2 entity2Observable, TestEntity3 entity3Observable, TestEntity4 entity4Observable, TestEntity5 entity5Observable) {
        this.entity1Observable = entity1Observable;
        this.entity2Observable = entity2Observable;
        this.entity3Observable = entity3Observable;
        this.entity4Observable = entity4Observable;
        this.entity5Observable = entity5Observable;
        return this;
    }


任何帮助将非常感激。

最佳答案

zip具有an overloads that receives an Iterable。这应该足以传递任何数量的项目。

09-26 02:18