使用Java var args

时间:2019-12-26 20:40:30

标签: java rx-java

我有以下可观察的东西

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

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

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