Run-time type information allows you to discover and use type information while the program is running.
Java recognizes objects and classes at runtime in two ways: (1) "traditional" RTTI, which assumes that we already know all types at compile time, and (2) "reflection" mechanism, which allows us to discover and use information about classes at runtime.
First, why need Rtti (run-time-type-information)
The basic purpose of object-oriented programming is to have the code manipulate only the reference of the base class, so that if you want to add a new class under the base class, the original code will not be affected.
For example:
The animal in the diagram is the base class, at the top, and the derived class expands downward.
Look first, what happens if we don't manipulate the base class?
If we write code that does not manipulate the animal base class, but the specific animal derived classes under the animal, such as: giraffes, etc., it is bound to cause our code to change over and over again. Because giraffes run by no means the leopard run, when you want to let the leopard run, you have to change the running of the giraffe, so that our object-oriented programming purposes are not reached.
So what can be considered object-oriented programming?
We only need to manipulate the dynamic bound running behavior of animals, so that in specific animals to cover the specific run behavior can be. When this is really running, the actual running behavior in the derived class is actually run. I call this trick " cheat ".
Examples of the code are:
Chapter 14. Type information (1)