Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Derive from specialized generic types

Is it possible to derive a class from a specialized generic type:

TGenericBase <T> = class
  // ...
end;

TSpecializedDerived = class (TGenericBase <String>)
  // ...
end;

Just wondering if this is possible at all...

EDIT Code works fine when I put it in a new project. Must be due to some other mistake; sorry about that

like image 728
jpfollenius Avatar asked Apr 11 '26 14:04

jpfollenius


1 Answers

Yes. I do it all the time. It's very useful. One of my favorite tricks goes something like this:

TSpecializedList = class(TObjectList<TMyType>)
public
 (extra methods specific to handling TMyType objects)
end;
like image 125
Mason Wheeler Avatar answered Apr 13 '26 12:04

Mason Wheeler