Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately @Dinesh/@DAJ's answer is incorrect. (@Romain's maybe too, but the wording is hard to parse.)</p> <p>Suppose you have a class <code>a.b.C</code> and you arrange that the same class gets loaded by two different classloaders. According to the specifications, you will end up with two distinct <code>Class</code> objects with the fully qualified name <code>a.b.C</code>, and from the type system perspective two distinct types. Each of the types will have a different set of static variables.</p> <p>The primary reference for this is <a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3.4" rel="nofollow">JLS 4.3.4</a> - paragraphs 2 and 3.</p> <p>You can infer that each reference type that is distinct (at runtime) will have a distinct set of statics from <a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.12.3" rel="nofollow">JLS 4.12.3</a>, <a href="http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.1.1" rel="nofollow">JLS 8.3.1.1</a>, <a href="http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4" rel="nofollow">JLS 12.4</a>, and other parts of the language spec.</p> <hr> <blockquote> <p>So basically, will the following statement always be true:</p> </blockquote> <pre><code>A.loadClass("MyClass").getField("myField").get(null) .equals(B.loadClass("MyClass").getField("myField").get(null)); </code></pre> <p>In general it won't. </p> <p>It will always be true in <em>some</em> cases, depending on how <code>MyClass</code> initializes <code>myField</code>. For instance, if the field is initialized to a literal String, then it will. </p> <p>(The trick to observing this is to arrange that <code>MyClass</code> is <em>actually loaded</em> by the two classloaders <code>A</code> and <code>B</code>, and not by a common ancestor classloader.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload