Casting (Cont’d)
if (animalArray[iIndex] instanceof Dog) {
d = (Dog) animalArray[iIndex];
evaluated at compile time.
- Legality of each line discernable without worrying about inter-statement dependencies, i.e., each line can stand by itself.
- Can be sure that code is legal (not sometimes-legal).A Good Use for Casting:
Resolving polymorphic ambiguities for the compiler.