【发布时间】:2008-11-06 23:13:10
【问题描述】:
我正在查看 Delphi 2009 试用版,但马上就遇到了泛型问题。
以下代码无法编译,我一点也不知道为什么它为 Equals() 方法提供 E2015:
type
TPrimaryKey<T> = class(TObject)
strict private
fValue: T;
public
constructor Create(AValue: T);
function Equals(Obj: TObject): boolean; override;
function GetValue: T;
end;
constructor TPrimaryKey<T>.Create(AValue: T);
begin
inherited Create;
fValue := AValue;
end;
function TPrimaryKey<T>.Equals(Obj: TObject): boolean;
begin
Result := (Obj <> nil) and (Obj is TPrimaryKey<T>)
and (TPrimaryKey<T>(Obj).GetValue = fValue);
end;
function TPrimaryKey<T>.GetValue: T;
begin
Result := fValue;
end;
为什么编译器认为fValue和GetValue()的结果不能比较?
【问题讨论】:
标签: delphi generics delphi-2009