Delphi 编译器看不到Spring4D TMultiMap重载构造函数(错误E2250)
我正在努力使用Spring4d1.2.2tMultiMap通用类。我想调用重载构造函数,编译器会抱怨:Delphi 编译器看不到Spring4D TMultiMap重载构造函数(错误E2250),delphi,spring4d,Delphi,Spring4d,我正在努力使用Spring4d1.2.2tMultiMap通用类。我想调用重载构造函数,编译器会抱怨: "E2250 There is no overloaded version of 'Create' that can be called with these arguments" 根据Spring4D源代码,参数是正确的类型 我设计了一个小的不做任何事情的程序来重现这个错误: program Spring4DMultiMapTest; {$APPTYPE CONSOL
"E2250 There is no overloaded version of 'Create' that can be called with these arguments"
根据Spring4D源代码,参数是正确的类型
我设计了一个小的不做任何事情的程序来重现这个错误:
program Spring4DMultiMapTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Generics.Collections,
Spring.Tests.Interception.Types,
Spring.Collections.MultiMaps,
Spring.Collections;
type
TMyKey = TPair<Double, Integer>;
TMyKeyEqualityComparer = class(TInterfacedObject, IEqualityComparer<TMyKey>)
function Equals(const Left, Right: TMyKey): Boolean; reintroduce;
function GetHashCode(const Value: TMyKey): Integer; reintroduce;
end;
function TMyKeyEqualityComparer.Equals(const Left, Right: TMyKey): Boolean;
begin
if Left.Key < (Right.Key - 1E-9) then
Result := TRUE
else if Left.Key > (Right.Key + 1E-9) then
Result := FALSE
else if Left.Value < Right.Value then
Result := TRUE
else
Result := FALSE;
end;
function TMyKeyEqualityComparer.GetHashCode(const Value: TMyKey): Integer;
begin
Result := Value.Value + Round(Value.Key * 1E6);
end;
var
Events : IMultiMap<TMyKey, Integer>;
KeyComparer : IEqualityComparer<TMyKey>;
begin
KeyComparer := TMyKeyEqualityComparer.Create;
// Next line triggers error: "E2250 There is no overloaded version of 'Create' that can be called with these arguments"
Events := TMultiMap<TMyKey, Integer>.Create(KeyComparer);
end.
在Spring4D源代码中,我发现以下声明:
TMultiMap<TKey, TValue> = class(TMultiMapBase<TKey, TValue>)
并且还声明了TMultiMap acestor:
TMultiMapBase<TKey, TValue> = class abstract(TMapBase<TKey, TValue>,
IMultiMap<TKey, TValue>, IReadOnlyMultiMap<TKey, TValue>)
有一个构造器:
constructor Create(const keyComparer: IEqualityComparer<TKey>); overload;
这是我要调用的构造函数。据我所知,我的参数KeyComparer的类型是正确的。但显然编译器不同意:-
如何修复此代码?您使用不同的IEqualityComparer类型
示例中的IEqualityComparer来自Spring.Tests.Interception.Types.pas。TMultiMap.Create构造函数中使用的构造函数在System.Generics.Defaults.pas中定义
如果您将“使用”部分更改为
您的示例将被编译
通过Delphi 10.3 U3和Spring4D 1.2.2测试,您可以使用不同的IEqualityComparer类型
示例中的IEqualityComparer来自Spring.Tests.Interception.Types.pas。TMultiMap.Create构造函数中使用的构造函数在System.Generics.Defaults.pas中定义
如果您将“使用”部分更改为
您的示例将被编译
通过Delphi10.3U3和Spring4d1.2.2测试,这不是实例化spring集合的常用方法。您通常调用返回接口的类方法。你是否因为某个特定的原因选择了不同的方式。另外,您使用的是哪个分支?我尝试使用TCollections.CreateMultiMap获得完全相同的结果。正常,因为它调用基础的同一构造函数。。。我两天前下载了Spring4D作为zip文件。发行说明说1.2.2.FWIW版不是有效的相等比较器。这不是实例化spring集合的常用方法。您通常调用返回接口的类方法。你是否因为某个特定的原因选择了不同的方式。另外,您使用的是哪个分支?我尝试使用TCollections.CreateMultiMap获得完全相同的结果。正常,因为它调用基础的同一构造函数。。。我两天前下载了Spring4D作为zip文件。发行说明说1.2.2.FWIW版不是有效的相等比较器。
uses
System.SysUtils,
Generics.Collections,
// Spring.Tests.Interception.Types,
Generics.Defaults,
Spring.Collections.MultiMaps,
Spring.Collections;