Generic programming

Generic programming #

Generic programming consists in writing algorithms while abstracting from data types, leaving the possibility for these data types to be specified as parameters.

Many statically typed imperative languages support such mechanisms: C++, C#, Go, Java, Rust, Typescript, etc. In functional programming languages (such as Haskell), generic programming is known as parametric polymorphism.

Java only integrated generic programming in 2004 (with Java 5).

Java’s generic types were influenced by the Standard Template Library for C++ (released in 1994), but the implementation (and semantics in some cases) is significantly different, based on a mechanism called type erasure (which guarantees backward compatibility with prior versions of Java).