O'Reilly logo
  • You Wang thinks this is interesting:

it is good programming practice to find out whether a cast will succeed before attempting it. Simply use the instanceof operator. For example:

From

Cover of Core Java® Volume I—Fundamentals, Tenth Edition

Note

use "instanceof" to check type