Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki Markup
In a JVM a class is identified by its fully-qualified class name AND its classloader. A class with the same name but different package name is different, and a class with the same fully-qualified name but which has been loaded with a different classloader is also different. According to  \[1\] §2.8.1, "Two classes are the _same class_ (and therefore the _same type_) if they are loaded by the same class loader and they have the same fully qualified name" \[JVMSpec 99 §2.8.1\].

You may frequently want to know whether a given object has a specific class, or whether 2 objects have the same class, for example, in implementing the equals() method. If the comparison is performed incorrectly, your code might assume that 2 objects are of the same class when they're not.

...