Java-like generics in D

Frank Benoit keinfarbton at googlemail.com
Sun Aug 12 06:01:01 PDT 2007


As addition to the existing templates, i think java like generics would
be very helpful for D.

The generic could be like this:
1) use the new keyword 'generic' instead of 'template'
2) Typeparameter can only be object or interface types
3) the compiled code does not know the exact type of the instantiation
parameter. (type erasure)
4) the compiler 'inserts' missing casts for the given instantiation type
parameters

Advantages:
5) "lightweight templates", because of no more object code duplication
for new instantiations.
6) the compiler can generate the object code independantly of the
intantiation code
7) no more errors like 'forward reference' for generic, because the
generic can compile without the knowledge of the exact types.

Does that make sense?




More information about the Digitalmars-d mailing list