Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Of course you cannot have int x and long x fields in the same class, just as you cannot have two methods with the same name and parameter list. But this is at the source level. JVM and bytecode have different rules. Consider this:</p> <p>package test;</p> <pre><code>public class Test { static int x; @Override protected Test clone() throws CloneNotSupportedException { return this; } public static void main(String[] args) { int y = x; } } </code></pre> <p>If you use a bytecode outline tool (I've used Andrey Loskutov's plugin for Eclipse) you will see in this line int Test.main()</p> <pre><code>GETSTATIC test/Test.x : I </code></pre> <p>This is how JVM loads value from field x, its full name is "test/Test.x : I". That gives you a hint that the field value is present in the field full name. </p> <p>It's no secret that javac is not the only means to create a class, there are tools/libraries to create bytecode directly, and they are free to create classes with fields with the same name but different type. Same goes for JNI.</p> <p>It's hard to show a working example of what I am trying to prove. But let's consider methods, a similar issue. Bytecode analisys shows that there are two methods in Test class with the same name and parameters which is not allowed by JLS:</p> <pre><code>protected clone()Ltest/Test; throws java/lang/CloneNotSupportedException protected volatile bridge clone()Ljava/lang/Object; throws java/lang/CloneNotSupportedException </code></pre> <p>The "bridge" method was added by javac because Test.clone() returns Test and this means it does not override Object.clone() which returns Object and this is because JVM thinks these two are different methods</p> <pre><code>1 clone()Ltest/Test; 2 clone()Ljava/lang/Object; </code></pre>
    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. This table or related slice is empty.
    1. 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