title: What magic makes object.getClass() in Java return a typed Class instance?
body: <p>In Java, <code>Object.getClass</code> has a type signature of <code>public final Class&lt;?&gt; getClass()</code>, but the JavaDoc comment mentions that it will really be "<code>Class&lt;? extends |X|&gt;</code> where |X| is the erasure of the static type of the expression on which <code>getClass</code> is called".</p>
  
  <p>This is indeed the case and enforced by the compiler, supported by the IDE:s etc, but what magic make this tick? Does the compiler treat this method in a special way? Does it actually generate an override of <code>getClass()</code> for each type?</p>
  
  <p>I understand that this is solely a compile time construct, at runtime it will not make any difference what the generic type parameter of Class is/was.</p>