您好,我想知道有什么比这更优雅的替代品:
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();
}
Run Code Online (Sandbox Code Playgroud)
播种替代品...
谢谢你的建议。
编辑:基类可能有许多子类,而不仅仅是两个,它们的数量可能会随着时间增长