我需要实现List装饰器类,它会在列表中发生任何更改时通知已注册的侦听器。我已从 AbstractListDecorator .jar!/index.html?org / apache / commons / collections15 / CollectionUtils.html“rel =”nofollow noreferrer“> org.apache.commons.collections15 并覆盖 add()等方法 addAll() remove(int) remove(E)等等。

但是有一些漏洞 - 例如,在默认情况下迭代List AbstractListDecorator.iterator()并调用 Iterator.remove()方法时,要么重写方法 remove(int) remove(E)不会调用。

是否有任何标准和安全措施来装饰这些东西?

谢谢。

有帮助吗?

解决方案

覆盖iterator()和listIterator()方法,并提供一个装饰迭代器,它将在调用remove()时通知侦听器。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top