I have a List
of interface type Criteria
within my class Query
.
List<Criteria> criteria = new ArrayList<Criteria>();
I have several concrete implementations of Criteria
. I want to give Query
a method that iterates through my criteria
list, and depending on the concrete type, execute some logic.
I'm presently doing this with instanceof
like so:
for(Criteria c : criteria) {
if(c instanceof ContextualCriteria){
// logic
}
...
}
Is this the only/best way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…