Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>What are the limitations of Java/C# generics?</h2> <p>Java generics are limited because it is not possible to do some tricks like in C++.</p> <p>To proof the claim <a href="http://en.wikipedia.org/wiki/Policy-based_design" rel="nofollow">here</a> is an C++ example that is impossible to reproduce with templates alone in Java.</p> <p>Policy based programming is a way to restrict the use of an (templated) class to other (possible) templated classes on inheritence at compile time.</p> <p><strong>What is the big deal of compile time generics vs runtime generics?</strong></p> <p>The deal is that the compiler knows everything about the possible runtime behaviour of the class/templates so it can do heavy optimizations that are (currently) impossible with an C#/Java/whatever runtime environment/compiler.</p> <p>A other good side of this is that the compiler can ensure that the instatiation of a combination of the templates is valid which means that there is no possibility that runtime-errors can happen like in Java/C# when the programmer want to instatiate new objects with an invalid combination.</p> <p><strong>What is the downside of C++ generics?</strong></p> <p>The downside is that the templates can get really complicated to read and understand and debug. This is (maybe) one of the reasons why the Java developers didn't want to have such a beast in a language.</p> <hr> <h2>What is possible with C++ Generics that is impossible with Java/C# generics?</h2> <p>In C++ is is possible to use other templates as template parameters which is impossible in C#/Java and which allows elegant tricks like template-metaprogramming.</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