Derive from specialized generic types

…衆ロ難τιáo~ 提交于 2020-03-19 06:01:05

问题


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


回答1:


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;


来源:https://stackoverflow.com/questions/793735/derive-from-specialized-generic-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!