Derive from specialized generic types

Derive from specialized generic types

少女情怀诗 发布于 2021-11-29 字数 399 浏览 933 回复 1 原文

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

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等往事风中吹 2022-06-07 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;