衍生自专门的泛型类型 [英] Derive from specialized generic types

查看:119
本文介绍了衍生自专门的泛型类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从一个专门的泛型类型派生一个类:

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

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

只是想知道这是否可能...



编辑当我将其放入新项目时,代码正常工作。必须是由于其他错误;对不起,

解决方案

是的。我一直这样做。这非常有用。我最喜欢的技巧之一就是这样的:

$ p $ $ code $ TSpecializedList = class(TObjectList< TMyType>)
public
(特定于处理TMyType对象的额外方法)
end;


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

解决方案

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;

这篇关于衍生自专门的泛型类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆