I have a List
of interface type Criteria
within my class Query
.
List criteria = new ArrayList
Well, you can...
if (ContextualCriteria.class.equals(c.getClass()) {
... though it's just a fancier-looking way of writing instanceof
. (Well, almost: this tests whether it is exactly the class, rather than the class of a subclass -- for that you want isAssignableFrom()
).
The right way to get rid of the smell is to implement a polymorphic method in Criteria
which is overridden in subclasses, for example.