*/ public class Box<T> { private T t; public void set(T t) { this.t = t; } public T get() { return t; } }

Box<Integer> integerBox; // użycie typu parametryzowanego

C# (typy generyczne)void SwapIfGreater<T>(ref T lhs, ref T rhs) where T : System.IComparable<T> { T temp; if (lhs.CompareTo(rhs) > 0)

temp = lhs; lhs = rhs; rhs = temp;

Haskell (polimorfizm parametryczny)-- Typ a -> a oznacza typ uniwersalnie kwantyfikowany: ∀ a. a -> a id' :: a -> a id' x = x

TypeScript (generics)function identity<Type>(arg: Type): Type { return arg; }

Zobacz też szablon (C++) szablon (D) polimorfizm metaprogramowanie

Przypisy

Kategoria:Paradygmaty programowania