Почему отличаются данные в breakpoint с "реальными"
Полный код
public class TestClass {
private MyObject myObjects = new MyObject(null);
private Queue<MyObject> myObjectsQueue = new LinkedList<>();
public void testStart(){
Completable.fromAction(()-> {
//каждые 500 млсекунды обновляем данные
myObjects.setNumber(getRandom(10, 20));
//добавляем в очередь
myObjectsQueue.add(myObjects); // понятно что мы меняем один обьект, а это ссылка
}).repeatWhen(success->success.delay(500, TimeUnit.MILLISECONDS))
.subscribeOn(Schedulers.computation())
.subscribe();
Completable.fromAction(()-> {
//каждые 5 секунд обрабатываем копию нашего листа (очереди)
obtain(new LinkedList<>(myObjectsQueue));
}).repeatWhen(success->success.delay(5, TimeUnit.SECONDS))
.subscribeOn(Schedulers.computation())
.subscribe();
}
private void obtain(Queue<MyObject> queue){
Log.d("MyTestQueue", "queue size " + queue.size());
//если остановить брекпоинтом, то видно что в очереди разные данные
//но когда пробегаемся они одинаковые
//вопрос в том что почему в брекпоинте данные разные?.
while (!queue.isEmpty()){
MyObject current = queue.poll();
Log.d("MyTestQueue", "currentObj value: " + current.getNumber());
}
}
private static class MyObject{
private Integer number;
public MyObject(Integer number) {
this.number = number;
}
public void setNumber(Integer number) {
this.number = number;
}
public int getNumber() {
return number;
}
}
private int getRandom(int min, int max){
Random r = new Random();
return r.nextInt(max - min + 1) + min;
}
}
dependency
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'
А при выводе в лог такие:
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
currentObj value: 14
Вопрос не в том что, почему данные одинаковые, а в том что, почему при просмотре в breakpoint они разные?
