Java:List< E>装饰器实现与通知
-
06-07-2019 - |
题
我需要实现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()时通知侦听器。
不隶属于 StackOverflow