I want to do something I have done often in Java:
I want to define a generic class C with a type parameter <T> such that T implements a given Interface I. Or in order to be more general, the implementation of C should take use of the fact that instances of T offer a given function f.
How can I do that? My idea would have been:
type
I = interface
function f: Boolean;
end;
generic C <T: I> = class
function g(t:T):Boolean;
end;
implementation
function C.g(t:T);
begin
g:=t.f;
end;
According to the language reference, this is syntactically not possible. Is there any other way to achieve this kind of genericity? Can I write generic code for a restricted variety of type parameters?
Thanks in advance!