I am trying to write a universal function that accepts the appropriate parameter types.
Delphi makes the correct type parameter in a simple argument to simple arguments.
eg:
type TFoo = class function Pair<T>(e1, e2: T): TList<T>; end;
calling this with aFoo.Pair(1, 2); works fine, but when I change the parameter signature to a generic type
type TFoo = class function InsertInto<T>(aList: TList<T>; aVal: T): TList<T>; end;
and try calling him
aFoo.InsertInto(TList<String>.Create, 'bar');
then the compiler complains about this:
E2010 Incompatible types: 'Generics.Collections.TList<uTest.TFoo.InsertInto.T>' and 'Generics.Collections.TList<System.String>'
Is there any way to write this (or similar) method so that the client does not have a type parameter specification?
aFoo.InsertInto<String>(TList<String>.Create, 'bar');
Alexander Konstantinov
source share