Differences and relations regarding getClass () and the instanceof

1. Purpose:

  When comparing whether a class and another class belong to the same class instance, and we usually can use instanceof getClass judged by both the two methods are equal, but both of the above judgment is different.

2. Distinction:

  , instanceof type checking rule is: whether belonging to the class or subclass of this class. Type of information is obtained by using getClass == equal to check whether the operation is a strict judgment, would not be considered inherited.

Guess you like

Origin www.cnblogs.com/quanhaijie/p/12191290.html