вторник, 13 мая 2008 г.

Be careful whith Collections and Maps in Axapta

Let`s review block of code listed below.

List list = new List(Types::String);

ListIterator iterator;
;
list.addEnd("a");
list.addEnd("b");
list.addEnd("c");
list.addEnd("d");

iterator = new ListIterator(list);

while (iterator.more())
{
if (iterator.value() == "b")
list.addEnd("e");

iterator.next();
}

info(list.toString());

There is instance of List class retaining arbitrary string values. ListIterator class is instantiated for traversing through elements in the list. What will happen when we try to add a new element in the list inside iteration block? New element will be added to collection! In Java for iterators implemented other behavior. If an iterator is obtained, modifying the underlying collection will throw a ConcurrentModificationException. Pay attantion to this difference.

Комментариев нет:

Отправить комментарий