How to judge whether two Class objects are the same in Java

How to judge whether two Class objects are the same

There are two necessary conditions to indicate whether two class objects are the same class in the JVM:

  1. The complete class name of the class must be the same, including the package name.

  2. The ClassLoader (referring to the ClassLoader instance object) that loads this class must be the same.

In other words, in the JVM, even if the two class objects (class objects) originate from the same Class file and are loaded by the same virtual machine, as long as the ClassLoader instance objects that load them are different, then the two class objects are different. equal.

Guess you like

Origin blog.csdn.net/qq_33626996/article/details/112850055