Overloads and Type Compatibility in Generics
Go Up to Generics Index
Generic methods can participate in overloading alongside non-generic methods by using the 'overload' directive. If overload selection between a generic method and a non-generic method would otherwise be ambiguous, the compiler selects the non-generic method.
type TFoo = class procedure Proc<T>(A: T); procedure Proc(A: String); procedure Test; end; procedure TFoo.Test; begin Proc('Hello'); // calls Proc(A: String); Proc<String>('Hello'); // calls Proc<T>(A: T); end;
Two non-instantiated generics are considered assignment compatible only if they are identical or are aliases to a common type.
Two instantiated generics are considered assignment compatible if the base types are identical (or are aliases to a common type) and the type arguments are identical.