I have a List
of interface type Criteria
within my class Query
.
List criteria = new ArrayList
You can also use:
for(Criteria c : criteria) {
if(c.getClass() == ContextualCriteria.class){
// logic
}
if ...
}
Note that Object#getClass() returns the runtime type of c
, so you can't reliably use this if ContextualCriteria
can be subclassed for example. To do this you would need to use Class#isAssignableFrom():
for(Criteria c : criteria) {
if(ContextualCriteria.class.isAssignableFrom(c)){
// logic
}
if ...
}