Generic Types

From The Oxygene Language Wiki
Jump to: navigation, search

This is a Language topic about Oxygene
 

Language Topics Introduction | Structured Overview | Grammar | Keywords | Functions



A generic type is a class, interface, record or delegate with one or more generic type parameters.

The members that use this type will have their actual type filled in at runtime by the Just-In-Time compiler. .NET comes with several built-in generic classes, e.g. the List<T> type, which is a dynamic list structure containing references to any number of type T. T can be any type at all, and List<T> will be a type-safe list of whatever type the developer desires.


A generic class looks like this:

type
  MyList<T> = class(System.Object, system.Collections.Generics.IEnumerable<T>)
    where T is class;
  private
    fData: array of T;
    fCount: Integer;
  public
   ...


To use this class, the generic type has to be defined in the type signature:

var
  Data: MyList<String>;
begin
  Data := new MyList<String>;
  Data.Add('Test');


See Also

Personal tools
Namespaces

Variants
Actions
Navigation
Getting Started
Sections
If you know
More
Toolbox