Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Also found <a href="http://www.artima.com/intv/generics.html" rel="nofollow noreferrer">this</a> conversation with Anders Hejlsberg that may be interesting too. To summarize points that Anders Hejlsberg made with some additional notes: <strong>Java generics were made for maximum compatibility with existing JVM</strong> that led to few odd things versus implementation you see in C#:</p> <ul> <li><p>Type erasure forces implementation to represent every generic parametrized value as <code>Object</code>. While compiler provides automatic casts between <code>Object</code> and more specific type, it <strong>does not remove the negative impact of the type casts and boxing on performance</strong> (e.g. <code>Object</code> is cast to specific type <code>MyClass</code> or <code>int</code> had to be boxed in <code>Integer</code>, which would be even more serious for C#/.NET if they followed type erasure approach due to user-defined value types). As Anders said: "you don't get any of the execution efficiency" (that reified generics enable in C#)</p></li> <li><p><strong>Type erasure makes information available at compile time not accessible during runtime</strong>. Something that used to be <code>List&lt;Integer&gt;</code> becomes just a <code>List</code> with no way to recover generic type parameter at runtime. <strong>This makes difficult to build reflection or dynamic code-generation scenarios around Java generics.</strong> More recent <a href="https://stackoverflow.com/a/4812643/44647">SO answer</a> shows a way around it via anonymous classes. But without tricks, something like generating code at runtime via reflection that gets elements from one collection instance and puts it to another collection instance can fail at runtime during execution of dynamically generated code: reflection doesn't help with catching mismatch in <code>List&lt;Double&gt;</code> versus <code>List&lt;Integer&gt;</code> in these situations.</p></li> </ul> <p>But +1 for the answer linking to Jonathan Pryor's <a href="http://www.jprl.com/Blog/archive/development/2007/Aug-31.html" rel="nofollow noreferrer">blog post</a>.</p>
 

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