12 ms·
What I find frustrating is that they seem to think that there are only two solutions - C++ (create a new type for each variant) or Java (erase the type informat
by AndrewDucker 12y ago
What I find frustrating is that they seem to think that there are only two solutions - C++ (create a new type for each variant) or Java (erase the type information).
C# does it differently to either - see here:
http://www.jprl.com/Blog/archive/development/2007/Aug-31.html http://www.jprl.com/Blog/archive/development/2007/Aug-31.htm...
(The section marked ".NET Implementation")
Edit: And here's Anders Hejlsberg talking about the design:
http://www.artima.com/intv/generics.html http://www.artima.com/intv/generics.html
- masklinn 12y ago> What I find frustrating is that they seem to think that there are only two solutions - C++ (create a new type for each variant) or Java (erase the type information). That, at least, is correct. Generics can be erased (compile-time only) or reified (generic type instances exist at runtime). C# uses reified generics, and Mono creates (created?) a reification for each parameter typeset, Microsoft's implementation creates the same underlying reification for all reference types as a space optimisation, but it still uses reified generics. There is a good helping of dishonesty in using C++ as the "reified generics" example though, as C++'s templates do significantly more than just reify generics (template specialisation, code generation, etc…) and that added to the interactions between templates and other language features makes them significantly more complex than e.g. C#'s, Rust's, Ceylon's, Kotlin's, and most other instances of reified generics.
- tomp 12y agoWhether generics are erased or reified is orthogonal to how they are implemented (whether the code is specialized or not).
- edgyswingset 12y agoThe argument brought up regarding compile times is also a misnomer. C#'s compiler pre-Roslyn is already very, very fast.