这段代码是线程安全的吗?
Observable<String> observable = ... // some observable that calls
// onNext from a background thread
observable
.scan(new ArrayList<String>(), (List<String> acc, String next) -> {
acc.add(next);
return acc;
})
.subscribe( list -> {
// do somethind with sequence of lists
...
});
我很好奇,因为 ArrayList 不是线程安全的数据结构。