Generic Methods
From RemObjects Software
This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.
A generic method is a method with 1 or more generic type parameters. It can be defined by placing a generic definition after the name of the method, like:
type MyClass = class method DoSomething<T>(Data: T); where T is IEnumerable; end;
Here the DoSomething method is defined with a single generic parameter called T that has to implement the IEnumerable interface. Inside the DoSomething function T can used like any other type that implements IEnumerable.
Calling a generic method can be done with and without specifying the generic parameter type. When the type is omitted the type is inferred from the parameter passed.
var Data: array of Strning := ['a', 'b', 'c']; aClass: MyClass; begin aClass.DoSomething<array of string>(Data); aClass.DoSomething(Data); // same as above
See Also
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Feature
