void ensureAllHaveParent( Collection c, Class parentClass ) {
for ( Iterator it = c.iterator(); it.hasNext(); ) {
Object o = it.next();
if ( ! ( o instanceof parentClass ) )... // WRONG!
if ( ! parentClass.isInstance( o ) )... // RIGHT!
}
}
Posted from cwinters.com; read original
One of those java features I should have known: class.isInstance() 0 Comments More | Login | Reply /