您好,我想知道有什么更优雅的替代方案来代替这样的东西:
class Base...
class A extends Base...
class B extends Base...
//iterator of colection containing mixed As and Bs i want to remowe Bs and do omething with As
while(iterator.hasNext()) {
Base next = iterator.next();
if(next instanceof A) // do something
if(next instanceof B)
iterator.remove();
}
看看有什么替代方案...
谢谢你的建议。
编辑:基类可能有许多子类,而不仅仅是两个,它们的数量可能会随着时间增长