views:

85

answers:

5

I'm curious which statically-typed languages have no generics support (and to a lesser extent which languages historically did not have generics), and how they deal with it.

Do users just cast all over the place? Is there some special sauce for basic collections, like lists and dictionaries, that allow those types to be generic?

Why do these languages not have generics? Is it to avoid potential complexity or other reasons?

A: 

Download java 1.4 or 1.3 and try it yourself.

Hint: Yes there will be probably many casts

How to deal: I've seen an organization forcing any API not to use collection (in the method declaration) but array to avoid confusion to the user. Alternative is to create a specific collection classes that only works with certain class for example StringList etc

nanda
+2  A: 

C—and historical C++, before it was called C++—requires you to either manually expand "generic" types into non-generics (i.e. the C preprocessor macro equivalent of C++ templates) or escape the type system (i.e. void pointers).

However, arrays (lists) are treated as composite types rather than a single type. You can have an array of shorts, for example, but you could not treat it the same as an array of chars or even of longs.

This isn't a really big problem in C, though inconvenient at times. It does represent a trade-off from 40 years ago, to put it in context.

Roger Pate