This is kind of a follow-up from my other question.
When I first heard about generics, it was before the release of Delphi 2009 (Where they introduced it first). I know it was supported in .Net before that, but I have yet to dig in that realm.
Reading about generics, I learned that it allowed class to have a variable argument to it, and that whatever value you passed to it would then be replaced through all the code of the class.
The way generics were described (or at least, what I understood generics allowed) was that, given the following declaration:
procedure TMyClass<T>.Init;
begin
FField := T.Create(nil);
end;
I assumed it would work. I assumed where the compile would fail is as follow:
begin
TMyClass<TComponent>.Create; //Works correctly
TMyClass<TObject>.Create; //Doesn't work, as even though it HAS a constructor, it has none that receive a single pointer parameter
TMyClass<string>.Create; //Doesn't work, not an object.
end;
Now, I well know I was wrong. So, what I wonder now, is there a technology/language feature that would support such a construct. Code templates perhaps? Generics in other programming languages? Or maybe something else?