When iterating over an Iterable
with a for
loop, the iteration variable could have the same type as the type returned by
the iterator (the item type of the Iterable
). This rule reports when a supertype of the item type is used for the variable instead, but
the variable is then explicitly downcast in the loop body.
Using explicit type casts instead of leveraging the language’s type system is a bad practice. It disables static type checking by the compiler for
the cast expressions, but potential errors will throw a ClassCastException
during runtime instead.