我正在尝试从 IOrderedDictionary 继承一个接口并实现继承的接口,见下文:
uses
Spring.Collections;
type
IAttributeCollection = interface(IOrderedDictionary<String,String>)
end;
INodeContents = interface(IAttributeCollection)
function Test: Boolean;
end;
TAttributeCollection = class(TInterfacedObject, IAttributeCollection)
private
FAttributes: IAttributeCollection;
function GetAttributes: IAttributeCollection;
public
constructor Create;
property Attributes: IAttributeCollection read GetAttributes implements
IAttributeCollection;
end;
TNodeContents = class(TAttributeCollection, INodeContents)
public
function Test: Boolean;
end;
此代码无法编译,在 TNodeContens 中,编译器错过了 Spring.Collections.IDictionary.GetItem 的实现(除了一些其他但不是所有成员)。
这看起来很奇怪,当我直接在单元中定义通用接口时,代码符合得很好(见下文)。
type
IOrderedDictionary<TKey, TValue> = interface(IInvokable)
end;
IAttributeCollection = interface(IOrderedDictionary<String,String>)
end;
INodeContents = interface(IAttributeCollection)
function Test: Boolean;
end;
TAttributeCollection = class(TInterfacedObject, IAttributeCollection)
private
FAttributes: IAttributeCollection;
function GetAttributes: IAttributeCollection;
public
constructor Create;
property Attributes: IAttributeCollection read GetAttributes implements
IAttributeCollection;
end;
TNodeContents = class(TAttributeCollection, INodeContents)
public
function Test: Boolean;
end;