作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如article所示,可以在 C# 中定义:
public class MyTreeNode<T> where T: MyTreeNode<T>
{
}
但是,在 Delphi 中,以下代码无法编译并提示“E2003 未声明的标识符:'MyTreeNode<>'”:
type
TMyTreeNode<T: TMyTreeNode<T>> = class
end;
正式术语似乎是 "self-referencing generics constraint" 。我想知道如何在 Delphi 中执行此操作?
PS:
Another useful article as David pointed out 。
Relevent SO post regarding Delphi and covariance / contravariance 。
最佳答案
Delphi 中没有办法表达这样的通用约束。此外,我相信在这种约束下,没有类型安全的方法可以实现 C# 中可以实现的目标。
关于delphi - 如何在Delphi中定义具有自引用泛型约束的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23245741/
我是一名优秀的程序员,十分优秀!