Generic programming
In computer science, generic types are data types with the possibility to specify type parameters. This is known as parametric polymorphism.
A generic type allows you to create data types that abstract from the underlying types. For a list of numbers, a list of characters and a list of dates basically would be programmed in the same way. The algorithms for inserting, searching and deleting would always run the same. It is therefore desirable to make the implementation of the list independently of these types.
In Java, for example, a generic list as follows would be defined:
In programming languages , there are basically two approaches to support generic types.
One is that GenerischerTyp
. NET When Microsoft takes a middle course, to combine the advantages of both methods: For all reference types as type parameters, the generic class uses the same native code because the internal representation ( a simple reference ) of all reference types is the same. When using value types as type parameters, a separate native code path is created for each value type at runtime in the first use.
Generic types in various programming languages
- C implements generic types using templates
- Generic programming in Java
- C # and other. NET languages provide generics since. NET 2.0
- In the programming language Ada generics for parameterization of packages are used.
- Delphi has since Delphi 2009 support for generics, Free Pascal supports generic classes since version 2.2.
- The programming language shank provides generic types for Flash, Javascript and server-side execution (all three areas in which no generics is otherwise possible)
- Haskell provides a very powerful type system
- Data type